Basic use methods of DatePicker and Datepickerdialog
1. What is DatePicker? Select the date of the control. DatePicker Dialog
Creating a datepickerdialog--is different from other controls and does not need to be dragged out of the XML file
1. Declare a listener, using anonymous inner classes :
Ondatesetlistener, this method will be triggered after clicking on the set in the image above.
Ondatesetlistener New Datepickerdialog.ondatesetlistener () { @Override publicvoidint intint dayofmonth) { + "-" Monthofyear + "-" dayofmonth); } };
This point shows that Ondatesetlistener is an interface that is declared inside the Datepickerdialog class. But we have said that abstract classes, interfaces these have abstract functions, can not be declared with new, then the anonymous inner class here?
Ondatesetlistener () After this constructor is followed by a curly brace,the Ondateset method implements the abstract method in the Ondatesetlistener (), so this interface has been implemented, is implemented in the middle of {}, so
Can be new, but implementing an interface requires a class, so there is no class. Java programming only starts in the No. 0 month. Only 11 months.
2, the replication oncreatedialog (int id) method: (When creating a dialog, must be created by Oncreatedialog)
// @Override protected Dialog Oncreatedialog (int ID) { switch (ID) { case date_picker_id: return new Datepickerdialog (this , ondatesetlistener , 2010,11,25); Generate a new Datepickerdialog object that needs Ondatesetlistenner} return null ; }
3, when using the direct call ShowDialog
ShowDialog (int id), pass in the ID, will call Oncreatedialog this method, can put dialog show out.
How many is Dec? This is obviously December, so the month is starting from 0.
Why is the month starting from 0 and the date not starting from 0?
Basic use methods of Android--datepicker and Datepickerdialog