Android之时间和日期DatePicker和TimePicker 博客分类: 技术总结 Android时间日期DatePickerTimePicker
时间和日期DatePicker和TimePicker
DatePicker用init指定DatePicker初始的年月日:
DatePicker.init(mYear, mMonth, mDay, new DatePicker.onDateChangedListener(){
Public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth){
mYear=year;
mMonth= monthOfYear;
mDay= dayOfMonth;
//update
}});
TimePicker用setOnTimeChangedListener()事件来处理时间改变:
TimePicker. setOnTimeChangedListener(new TinePicker.onTimeChangedListener(){
Public void onTimeChanged(TimePicker view, int hourOfDay, int minute){
hourOfDay= hourOfDay;
minute= minute;
//update
}
});
Andriod还提供了动态修改日期和时间的API:DataPickerDialog与TimePickerDialog。他们以Dialog的形式弹出显示时间。
Button.setOnClickListener(new View.onClickListener(){
Public void onCLick(view v ){
New DatePickerDialog(classname.this, new DatePickerDialog.onDateSetListener(){
Public void onDateSet(DatePicker view, int year, int month, int day){
//update时间
}}, mYear, mMonth, mDay).show();}});
Button.setOnClickListener(new View.onClickListener(){
Public void onCLick(view v ){
New TimePickerDialog(classname.this, new TimePickerDlalog.onTimeSetListener(){
Public void onTimeSet(TimePicker view, int hour, int minute){
//update
}},mHour, mMinute, true).show();
时钟对象AnalogClock
推荐阅读
-
Android之时间和日期DatePicker和TimePicker 博客分类: 技术总结 Android时间日期DatePickerTimePicker
-
Android之日期时间选择控件DatePicker和TimePicker实例
-
Android之日期时间选择控件DatePicker和TimePicker实例
-
Android开发之DatePicker和TimePicker实现选择日期时间功能示例
-
Android UI控件系列:DatePicker,TimePicker(日期和时间选择)
-
Android开发之DatePicker和TimePicker实现选择日期时间功能示例
-
Android UI控件系列:DatePicker,TimePicker(日期和时间选择)