Android Development Datepickerdialog and Timepickerdialog features and usage

Source: Internet
Author: User

The function of Datepickerdialog and Timepickerdialog is relatively simple, the usage is very simple, as long as the following two steps can be.

?  Create Datepickerdialog, Timepickerdialog instances with the New keyword, and invoke their show () method to display the Date selection dialog box and the Time Selection dialog box.

?  For Datepickerdialog, timepickerdialog binding listener, this can ensure that the user through Datepickerdialog, Timepickerdialog set event is trigger listener, This allows you to get user-set events through the listener.

Timepickerdialog (Time selection dialog box) Overview:

A dialog box that uses Timepicker to provide a time selection for the user.

class Structure:

Java.lang.Object   ? android.app.Dialog    android.app.AlertDialog?     android.app.TimePickerDialog

Construction Method:

Public constructors

 

timepickerdialog (context  context,  Timepickerdialog.ontimesetlistener  callback, int hourofday, int minute, Boolean Is24hourview)

timepickerdialog (context  context, int theme,  Timepickerdialog.ontimesetlistener  callback, int hourofday, int minute, Boolean Is24hourview)

Description

Public timepickerdialog (context context, Timepickerdialog.ontimesetlistener Callback,inthourofday, int minute, Boolean is24hourview)

Parameters:

parameter

Description

Context

To run the component's activity.

CallBack

When the user chooses a good time, notifies the app of the callback function.

Hourofday

for the initial hour.

Minute

The initial minute.

Is24hourview

Whether the 24-hour system is used.

Public timepickerdialog (Context context,int teme, timepickerdialog.ontimesetlistener Callback,int hourofday, int minute, Boolean is24hourview)

Parameters:

Parameters

Description

Context

Run the component's activity.

Teme

Apply the theme on the Time selection dialog box.

CallBack

Notifies the application of the callback function after the user has chosen a good time.

Hourofday

The initial hour.

Minute

The initial minute.

Is24hourview

Whether to use the 24-hour system.

Public Method:

Public Methods

void

OnClick (dialoginterface Dialog, int which)

This method is called back when the button on the dialog box is clicked.

void

onrestoreinstancestate (Bundle savedinstancestate)

from a previously saved Bundle restores the status of the dialog box in the

Bundle

onsaveinstancestate ()

saves the State of the dialog box to Bundle in .

void

ontimechanged (timepicker view, int hourofday, int minute)

Callback the method when the time is changed.

void

UpdateTime (int hourofday, int minutofhour)

Update Time

Example:
public static class Timepickerfragment extends Dialogfragment                            implements Timepickerdialog.ontimesetlistener {    @Override public    Dialog oncreatedialog (Bundle savedinstancestate) {//Use the current time as the        default VA Lues for the picker        final Calendar c = calendar.getinstance ();        int hour = C.get (calendar.hour_of_day);        int minute = C.get (Calendar.minute);        Create a new instance of Timepickerdialog and return it        return new Timepickerdialog (Getactivity (), this, hour, minu Te,                Dateformat.is24hourformat (Getactivity ()));    }    public void Ontimeset (timepicker view, int hourofday, int. minute) {//do something with the time chosen by the        user< c13/>}}


Datepickerdialog (Time selection dialog box) Overview:

A simple dialog box with DatePicker that provides the user with a date selection.

class Structure:
Java.lang.Object   ? android.app.Dialog    android.app.AlertDialog?     android.app.DatePickerDialog
Construction Method:

Public constructors

datepickerdialog " Span style= "COLOR: #222222" > ( context &NBSP;CONTEXT,&NBSP; datepickerdialog.ondatesetlistener  callback, int year, int monthofyear, int dayofmonth)

Datepickerdialog (context context, int theme, datepickerdialog.ondatesetlistener callBack, int year, int monthofyear, int dayofmonth)

Description

Public datepickerdialog(context context, Datepickerdialog.ondatesetlistener callBack, int year, int monthofyear, intdayofmonth)

Parameters:

Parameters

Description

Context

Run the component's activity.

CallBack

Notifies the application of the callback function after the user has selected a date.

Year

The initial year.

Monthofyear

The initial month.

DayOfMonth

The initial day.

Public datepickerdialog(context context, int theme, Datepickerdialog.ondatesetlistener callBack, int year, int monthofyear, intdayofmonth)

Parameters:

Parameters

Description

Context

Run the component's activity.

Theme

Apply the theme on the Date selection dialog box.

CallBack

Notifies the application of the callback function after the user has selected a date.

Year

The initial year.

Monthofyear

The initial month.

DayOfMonth

The initial day.

Public Method:

Public Methods

DatePicker

Getdatepicker ()

Gets the Date selection dialog box.

void

OnClick (dialoginterface Dialog, int which)

This method is called back when the button on the dialog box is clicked.

void

ondatechanged (DatePicker View, int year, int month, Int. day)

Callback the method when the date changes.

void

onrestoreinstancestate (Bundle savedinstancestate)

This method is called back when the button on the dialog box is clicked.

Bundle

onsaveinstancestate ()

saves the State of the dialog box to Bundle the.

void

updatedate (int year, int monthofyear, int dayofmonth)

Sets the current date.

 Example:
public static class Datepickerfragment extends Dialogfragment                            implements Datepickerdialog.ondatesetlistener {    @Override public    Dialog oncreatedialog (Bundle savedinstancestate) {//Use the current date as the        default Da Te in the picker        final Calendar c = calendar.getinstance ();        int year = C.get (calendar.year);        int month = C.get (calendar.month);        int day = C.get (calendar.day_of_month);        Create a new instance of Datepickerdialog and return it        return new Datepickerdialog (Getactivity (), this, year, Mont h, day);    }    public void Ondateset (DatePicker view, int year, int month, Int. day) {        //do something with the date chosen by the US Er    }}


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.