Functional classification: Life Supported platforms: Android Operating environment: Eclipse Development language: Java Development tool: Eclipse Source code size: 90.47KB Source code download address: http://down..com/data/1977586 Source code introduction Attached is the source code of a custom date and time control (SelectTime) for the Android platform. From Android Bus address: http://www.apkbus.com/forum.php?mod=viewthread&tid=174518&extra= Source code running screenshot Source code snippet - package com.widget.time;
-
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
-
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
-
- public class MainActivity extends Activity {
- WheelMain wheelMain;
- EditText txttime;
-
- Button btnselecttime1, btnselecttime2, btnselecttime3;
-
- int year, month, day, hour, min;
-
- LayoutInflater inflater;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super .onCreate(savedInstanceState);
- setContentView(R.layout.main);
- txttime = (EditText) findViewById(R.id.txttime);
- btnselecttime1 = (Button) findViewById(R.id.button1);
- btnselecttime2 = (Button) findViewById(R.id.button2);
- btnselecttime3 = (Button) findViewById(R.id.button3);
-
- String yyyy = null ;
- SimpleDateFormat formatter = new SimpleDateFormat( "yyyy" );
- Date curDate = new Date(System.currentTimeMillis());
- yyyy = formatter.format(curDate);
-
- Log.e( "-------------" , yyyy);
-
- Calendar calendar = Calendar.getInstance();
-
- year = calendar.get(Calendar.YEAR);
- month = calendar.get(Calendar.MONTH);
- day = calendar.get(Calendar.DAY_OF_MONTH);
- hour = calendar.get(Calendar.HOUR_OF_DAY);
- min = calendar.get(Calendar.MINUTE);
-
- inflater = LayoutInflater.from(MainActivity. this );
-
- btnselecttime1.setOnClickListener( new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
-
- final View timepickerview = inflater.inflate(
- R.layout.timepicker, null );
- ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
-
- wheelMain = new WheelMain(timepickerview, 0 );
- wheelMain.screenheight = screenInfo.getHeight();
- wheelMain.initDateTimePicker(year, month, day, hour, min);
-
- new AlertDialog.Builder(MainActivity. this )
- .setTitle( "Select time" )
- .setView(timepickerview)
- .setPositiveButton( "OK" ,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- txttime.setText(wheelMain.getTime());
- }
- }).setNegativeButton( "Cancel" , null ).show();
-
- }
- });
-
- btnselecttime2.setOnClickListener( new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- LayoutInflater inflater = LayoutInflater
- .from(MainActivity. this );
- final View timepickerview = inflater.inflate(
- R.layout.timepicker, null );
- ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
-
- wheelMain = new WheelMain(timepickerview, 1 );
- wheelMain.screenheight = screenInfo.getHeight();
- wheelMain.initDateTimePicker(year, month, day, hour, min);
-
- new AlertDialog.Builder(MainActivity. this )
- .setTitle( "Select Date" )
- .setView(timepickerview)
- .setPositiveButton( "OK" ,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- txttime.setText(wheelMain.getTime());
- }
- }).setNegativeButton( "Cancel" , null ).show();
-
- }
- });
-
- btnselecttime3.setOnClickListener( new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- LayoutInflater inflater = LayoutInflater
- .from(MainActivity. this );
- final View timepickerview = inflater.inflate(
- R.layout.timepicker, null );
- ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
-
- wheelMain = new WheelMain(timepickerview, 2 );
- wheelMain.screenheight = screenInfo.getHeight();
- wheelMain.initDateTimePicker(year, month, day, hour, min);
-
- new AlertDialog.Builder(MainActivity. this )
- .setTitle( "Select Year" )
- .setView(timepickerview)
- .setPositiveButton( "OK" ,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- txttime.setText(wheelMain.getTime());
- }
- }).setNegativeButton( "Cancel" , null ).show();
-
- }
- });
- }
- }
Source code download address: http://down..com/data/1977586 |