Android Datepickerdialog Timepickerdialog

Source: Internet
Author: User

1<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"2Android:layout_width= "Match_parent"3android:layout_height= "Match_parent"4android:orientation= "Vertical" >5 6<Button7Android:layout_width= "Match_parent"8android:layout_height= "Wrap_content"9android:onclick= "Datepickerdialog"Tenandroid:text= "Datepickerdialog"/> One      A<Button -Android:layout_width= "Match_parent" -android:layout_height= "Wrap_content" theandroid:onclick= "Timepickerdialog" -android:text= "Timepickerdialog"/> -  -</LinearLayout>
Activity_main.xml
1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7     }8 9     /**Ten * Both Datepickerdialog and timepickerdialog inherit from Alertdialog, and the basic method is the same as Datapicker and Timepicker components, One * Only call the show () method of dialog to show that the callback listener is passed in the constructor method . A      * @paramv -      */ -     intYear =calendar.getinstance (). get (calendar.year); the     intmonth =calendar.getinstance (). get (Calendar.month); -     intDayOfMonth =calendar.getinstance (). get (Calendar.day_of_month); -      Public voidDatepickerdialog (View v) { -Datepickerdialog dialog =NewDatepickerdialog (mainactivity. This,NewOndatesetlistener () { + @Override -              Public voidOndateset (DatePicker view,intYearintMonthintdayofmonth) { +Toast.maketext (mainactivity. This, year+ "-" + (month+1) + "-" +DayOfMonth, Toast.length_short). Show (); A                  at             } - }, year, month, DayOfMonth); - dialog.show (); -     } -      -     intHourofday =calendar.getinstance (). get (Calendar.hour_of_day); in     intminute =calendar.getinstance (). get (Calendar.hour_of_day); -      Public voidTimepickerdialog (View v) { toTimepickerdialog dialog =NewTimepickerdialog (mainactivity. This,NewOntimesetlistener () { +              - @Override the              Public voidOntimeset (Timepicker view,intHourofday,intminute) { *Toast.maketext (mainactivity. This, hourofday+ ":" +minute, Toast.length_short). Show (); $             }Panax Notoginseng}, Hourofday, minute,true); - dialog.show (); the     } +}
Mainactivity.java

Android Datepickerdialog Timepickerdialog

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.