android dialog box (iii) Datepickerdialog and Timepikerdialog

Source: Internet
Author: User

Have time to write a date time together custom Time selection dialog box

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "Match_ Parent "android:paddingbottom=" @dimen/activity_vertical_margin "android:paddingleft=" @dimen/activity_horizontal_ Margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_vertical_        Margin "tools:context=" com.example.dateandtimedialog.MainActivity "> <button android:id=" @+id/button1 "    Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "Show date dialog box"/> <button android:id= "@+id/button2" android:layout_width= "fill_parent" android:layout_height= "Wra P_content "android:layout_below=" @+id/button1 "android:text=" Show time dialog box "/></RELATIVELAYOUT> 
Package Com.example.dateandtimedialog;import Java.util.calendar;import Android.app.activity;import Android.app.datepickerdialog;import Android.app.timepickerdialog;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.datepicker;import Android.widget.timepicker;import Android.widget.toast;public class MainActivity Extends Activity {private Button button1; private int year;private int monthofyear;private int dayofmonth;private Button b  Utton2; private int hourofday;private int minute; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.main); button1 = (Button) Findviewbyid (r.id.button1); button2 = (Button) Findviewbyid (R.id.button2);//initialization of month and day calendar calendar = Calendar.getinstance (); year = Calendar.get (calendar.year); Monthofyear = Calendar.get (calendar.month);d ayofmonth = Calendar.get (calendar.day_of_month); HourOfDay = Calendar.get (CAlendar. Hour_of_day); minute = Calendar.get (Calendar.minute); Button1.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubdatepickerdialog Datepickerdialog = new Datepick Erdialog (mainactivity.this,new Datepickerdialog.ondatesetlistener () {@Overridepublic void Ondateset (DatePicker view , int year, int monthofyear, int dayofmonth) {//The user is selected when the trigger//the specific month here returns the smaller than the actual 1monthOfYear = monthofyear+1; String string = year+ "year" +monthofyear+ "month" +dayofmonth+ "Day"; Toast.maketext (Mainactivity.this, String, 1). Show ();}, year, Monthofyear, DayOfMonth);d atepickerdialog.show ();}); Button2.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method stub//whether the last parameter table is a 24-hour form timepickerdialog Timepickerdialog = new Timepickerdialog (Mainactivity.this, new Timepickerdialog.ontimesetlistener () {@Overridepublic void Ontimeset (timepicker view, int hourofday, int minute) {// TODO auto-generated Method stubstring String = hourofday+ "When" +minute+ "minute"; Toast.maketext (Mainactivity.this, String, 1). Show ();}}, Hourofday, minute, true); Timepickerdialog.show ();}});}}

android dialog box (iii) Datepickerdialog and Timepikerdialog

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.