Basic use methods of Android--datepicker and Datepickerdialog

Source: Internet
Author: User

Basic use methods of DatePicker and Datepickerdialog

1. What is DatePicker? Select the date of the control. DatePicker Dialog

Creating a datepickerdialog--is different from other controls and does not need to be dragged out of the XML file

1. Declare a listener, using anonymous inner classes :

Ondatesetlistener, this method will be triggered after clicking on the set in the image above.

Ondatesetlistener New Datepickerdialog.ondatesetlistener () {            @Override            publicvoidint  intint  dayofmonth) {                + "-" Monthofyear +  "-" dayofmonth);               }        };

This point shows that Ondatesetlistener is an interface that is declared inside the Datepickerdialog class. But we have said that abstract classes, interfaces these have abstract functions, can not be declared with new, then the anonymous inner class here?

Ondatesetlistener () After this constructor is followed by a curly brace,the Ondateset method implements the abstract method in the Ondatesetlistener (), so this interface has been implemented, is implemented in the middle of {}, so

Can be new, but implementing an interface requires a class, so there is no class. Java programming only starts in the No. 0 month. Only 11 months.

2, the replication oncreatedialog (int id) method: (When creating a dialog, must be created by Oncreatedialog)

 //   @Override  protected  Dialog Oncreatedialog (int   ID) { switch   (ID) { case   date_picker_id:  return  new Datepickerdialog (this , ondatesetlistener   , 2010,11,25);  Generate a new Datepickerdialog object that needs Ondatesetlistenner}  return  null  ; }

3, when using the direct call ShowDialog

ShowDialog (int id), pass in the ID, will call Oncreatedialog this method, can put dialog show out.

How many is Dec? This is obviously December, so the month is starting from 0.

Why is the month starting from 0 and the date not starting from 0?

Basic use methods of Android--datepicker and Datepickerdialog

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.