标签:
监测日期改变的监听器:
OnDateChangedListener和OnTimeChangedListener()
当用户改变Datepicker里的年、月、日时,将触发OnDateChangedListener的OnTimeChange事件。
当用户更改TimePicker里的时、分、时,将触发OnTimeChangedListener监听器的OnTimeChanged事件
OnDateSetListener和OnTimeSetListener()
当用户更改了DatePickerDialog里的年、月、日时,将触发OnDateSetListener监听器的onDateSet()事件
当用户更改了TimePickerDialog里的时,分时,将触发OnTimeSetListener监听器的onTimeSet()事件。
public class MainActivity extends Activity {
private TimePicker timePicker;
private DatePicker datePicker ;
private Calendar calendar ;
private int year ;
private int month ;
private int day ;
private int hour;
private int minute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
calendar=Calendar. getInstance();
year= calendar.get( calendar. YEAR);
month= calendar.get( calendar. MONTH);
day= calendar.get( calendar. DAY_OF_MONTH);
setTitle( year+ month+ day);
datePicker=(DatePicker) findViewById(R.id.datePicker1);
timePicker=(TimePicker) findViewById(R.id.timePicker1);
//datepicker 初始化
datePicker.init(year , month , day , new OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
setTitle(year+ ""+monthOfYear+1+"" +dayOfMonth);
}
});
}
Android DatePicker和TimePicker
标签:
原文地址:http://www.cnblogs.com/stareblankly/p/4829271.html