Today because of business requirements, choose Start time and end time, need to implement a time selector, naturally think of the use of the system's time selector
The effect is as follows:
It's also easy to achieve this effect
Calendar C =newnew Datepickerdialog.ondatesetlistener () { @Override Public void int int int dayofmonth) { } }, C.get (Calendar.year), C.get (Calendar.month), C.get (Calendar.day_of_month));
Dialog.show ();
The original test machine is mostly 4.0 machines, the code runs with a bug, the above Ondatesetlistener callback will be called two times
So add code to control, add variable I to control
Calendar C =calendar.getinstance ();intI=1;d Ialog=NewDatepickerdialog (Getactivity (),NewDatepickerdialog.ondatesetlistener () {@Override Public voidOndateset (DatePicker view,intYearintMonthofyear,intdayofmonth) { if(i% 2 = = 0) {Changedialog (year, monthofyear, DayOfMonth); } I++; }}, C.get (Calendar.year), C.get (Calendar.month), C.get (calendar.day_of_month));d ialog.show ();
Run finished this thought there is no problem, the 4.x machine works well, but later on the 5.x machine found a bug, this callback will only execute once
Keng
So add the version code of the Judgment system:
Calendar C =calendar.getinstance ();intI=1;d Ialog=NewDatepickerdialog (Getactivity (),NewDatepickerdialog.ondatesetlistener () {@Override Public voidOndateset (DatePicker view,intYearintMonthofyear,intdayofmonth) { if(build.version.sdk_int>20) {Changedialog (year, monthofyear, DayOfMonth); }Else{ if(i% 2 = = 0) {Changedialog (year, monthofyear, DayOfMonth); } I++; }}, C.get (Calendar.year), C.get (Calendar.month), C.get (calendar.day_of_month));d ialog.show ();
The code first to determine the system version number before the operation of which
Changedialog (year, Monthofyear, DayOfMonth) is my own business logic,
Blog record, convenient to have this problem of children's shoes helpful!
Time picker, solutions for different system version differences