Android Development Datepickerdialog and Timepickerdialog use

Source: Internet
Author: User

Choose from the form of a dialog box. In particular, it feels datepickerdialog is much better than datepicker when the user chooses to interact.

Datepickerdialog and Timepickerdialog are well encapsulated, and for developers, direct invocation is very simple.




Demo Example:

public class Mainactivity extends Activity {Button button,button2; @Overridepublic void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);} public void Dateclick (View v) {Calendar calendar = calendar.getinstance ();D atepickerdialog datepickerdialog = new Datepic Kerdialog (Mainactivity.this, New Ondatesetlistener () {@Overridepublic void Ondateset (DatePicker arg0, int year,int monthofyear, int dayofmonth) {//Do what you want}}, Calendar.get (Calendar.year), Calendar.get (Calendar.month), Calendar.get ( calendar.day_of_month));d atepickerdialog.show ();} public void Timeclick (View v) {Calendar calendar = calendar.getinstance (); Timepickerdialog dialog = new Timepickerdialog (mainactivity.this, New Ontimesetlistener () {@Overridepublic void Ontimeset (timepicker arg0, int arg1, int arg2) {//Do what you want}}, Calendar.get (Calendar.hour_of_day), Calendar.get ( Calendar.minute), True);d ialog.show ();}}
Activity_main.xml

<linearlayout 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:orientation= "vertical"    tools:context= "${relativepackage}.${activityclass}" >    <button        android:id= "@+id/but"        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"        android:onclick= "Dateclick"        android:text= "click"/>    <button        android:id= "@+id/but2"        Android:layout_width= "Wrap_content"        android:layout_height= "wrap_content"        android:onclick= "TimeClick"        android:text= "click"/></linearlayout>


Android Development Datepickerdialog and Timepickerdialog use

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.