Android DatePicker and Timepicker

Source: Internet
Author: User

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

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.