Time picker, solutions for different system version differences

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.