功能分类:生命支持平台:Android运行环境:Eclipse开发语言:Java开发工具:Eclipse源代码大小:90.47KB源代码下载地址:http://down.51cto.com/data/1977586源代码介绍附件一Android平台自定义日期时间控件(SelectTime)源码。来自Android总线地址:http://www.apkbus.com/forum.php?mod=viewthread&tid=174518&extra=源代码运行截图源代码片段packagecom.widget.time;importjava.text.SimpleDateFormat;importjava.util.Calendar;导入java。util.Date;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.content.DialogInterface;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view。View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;publicclassMainActivityextendsActivity{WheelMainwheelMain;EditTexttxttime;Buttonbtnselecttime1,btnselecttime2,btnselecttime3;intyear,month,day,hour,min;LayoutInflaterinflater;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);txttime=(EditText)findViewById(R.id.txttime);btnselecttime1=(按钮)findViewById(R.id.button1);btnselecttime2=(按钮)findViewById(R.id.button2);btnselecttime3=(按钮)findViewById(R.id.button3);Stringyyyy=null;SimpleDateFormatformatter=newSimpleDateFormat("yyyy");DatecurDate=newDate(System.currentTimeMillis());//获取当前时间yyyy=formatter.format(curDate);Log.e("------------",yyyy);Calendarcalendar=Calendar.getInstance();year=calendar.get(Calendar.YEAR);month=calendar.get(Calendar.MONTH);day=calendar.get(日历。DAY_OF_MONTH);hour=calendar.get(Calendar.HOUR_OF_DAY);min=calendar.get(Calendar.MINUTE);inflater=LayoutInflater.from(MainActivity.this);btnselecttime1.setOnClickListener(newOnClickListener(){@OverridepublicvoidonClick(Viewarg0){finalViewtimepickerview=inflater.inflate(R.layout.timepicker,null);ScreenInfoscreenInfo=newScreenInfo(MainActivity.this);wheelMain=newWheelMain(timepickerview,0);wheelMain.screenheight=screenInfo.getHeight();wheelMain.initDateTimePicker(year,month,day,hour,min);newAlertDialog.Builder(MainActivity.this).setTitle("选择时间").setView(timepickerview).setPositiveButton("确定",newDialogInterface.OnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){txttime.setText(wheelMain.getTime());}}).setNegativeButton("取消",null).show();}});btnselecttime2.setOnClickListener(newOnClickListener(){@OverridepublicvoidonClick(Viewarg0){LayoutInflaterinflater=LayoutInflater.from(MainActivity.this);finalViewtimepickerview=inflater.inflate(R.layout.timepicker,null);ScreenInfoscreenInfo=newScreenInfo(MainActivity.this);wheelMain=newWheelMain(timepickerview,1);wheelMain.screenheight=screenInfo.getHeight();wheelMain.initDateTimePicker(year,month,day,hour,min);newAlertDialog.Builder(MainActivity.this).setTitle("选择日期").setView(timepickerview).setPositiveButton("确定",newDialogInterface.OnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){txttime.setText(wheelMain.getTime());}}).setNegativeButton("取消",null).show();}});btnselecttime3.setOnClickListener(newOnClickListener(){@OverridepublicvoidonClick(Viewarg0){LayoutInflaterinflater=LayoutInflater.from(MainActivity.this);finalViewtimepickerview=inflater.inflate(R.layout.timepicker,null);ScreenInfoscreenInfo=newScreenInfo(MainActivity.this);wheelMain=newWheelMain(timepickerview,2);wheelMain.screenheight=screenInfo.getHeight();wheelMain.initDateTimePicker(year,month,day,hour,min);newAlertDialog.Builder(MainActivity.this).setTitle("选择年份").setView(timepickerview).setPositiveButton("确定",newDialogInterface.OnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){txttime.setText(wheelMain.getTime());}}).setNegativeButton("取消消",null).show();}});}}源代码下载地址:http://down.51cto.com/data/1977586
