欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android之时间和日期DatePicker和TimePicker 博客分类: 技术总结 Android时间日期DatePickerTimePicker 

程序员文章站 2024-03-16 19:16:16
...

时间和日期DatePickerTimePicker

DatePickerinit指定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

}});

 

TimePickersetOnTimeChangedListener()事件来处理时间改变:

TimePicker. setOnTimeChangedListener(new TinePicker.onTimeChangedListener(){

  Public void onTimeChanged(TimePicker view, int hourOfDay, int minute){

   hourOfDay= hourOfDay;

minute= minute;

   //update

}

});

 

Andriod还提供了动态修改日期和时间的APIDataPickerDialogTimePickerDialog。他们以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