Monitor date change listener: Ondatechangedlistener and Ontimechangedlistener () when the user changes the year, month, and day in the DatePicker, the Ondatechangedlistener will be triggered on Timechange event. When the user changes the time, minute, and time in the Timepicker, the Ontimechangedlistener Listener's ontimechanged event is triggered Ondatesetlistener and Ontimesetlistener () when the user is more Changing the year, month, and day in Datepickerdialog will trigger the Ondateset () event of the Ondatesetlistener listener when the user changes the Timepickerdialog, the Tick, The Ontimeset () event that will trigger the Ontimesetlistener listener.
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 initialization 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 and Timepicker