Android Study Notes-datepicker

Source: Internet
Author: User

<1> Introduction

A calendar Layout View with year, month, and day selected

<2> class inheritance

Java. Lang. Object

Android. View. View

Android. View. viewgroup

Android. widget. framelayout

Android. widget. datepicker

<3> Method

Public int getdayofmonth ()

Obtain the number of days selected

Public int getmonth ()

Obtain the selected month. (Note: The returned value is 0 .. 11, which must be displayed with + 1)

Public int getyear ()

Obtain the selected year

Public void Init (INT year, int monthofyear, int dayofmonth, datepicker. ondatechangedlistener)

Initialization status. (Translator's note: Initialize year, month, and day)

Parameters

Year's first yearNew Date ()+ 1900 is required during the year of initialization, as shown below:Date. getyear ()
+ 1900
)

Monthofyear initial month.

The first day of dayofmonth.

Ondatechangedlistener
Event listening that notifies the user when the date changes. It can be null ).

Public void setenabled (Boolean enabled)

Set the view activation status. The activation status varies with the subclass.

Parameters

If enabled is set to true, the view is started. If enabled is set to true, the view is disabled.

Public void updatedate (INT year, int monthofyear, int dayofmonth)

Update date

Example:

Package android. test; import android. app. activity; import android. OS. bundle; import android. widget. datepicker; import android. widget. toast; public class testactivity extends activity {/** called when the activity is first created. */private datepicker = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); datepicker = (datepicker) findviewbyid (R. id. datepicker); string date = "year:" + datepicker. getyear () + "month:" + datepicker. getmonth () + "day:" + datepicker. getdayofmonth (); toast. maketext (testactivity. this, date, toast. length_short ). show ();}}

 

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "datepicker"/> <datepicker Android: Id = "@ + ID/datepicker" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"/> </linearlayout>

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.