DatePicker Date and Time Control, datepicker date Control

Source: Internet
Author: User

DatePicker Date and Time Control, datepicker date Control
DatePicker Date and Time Control

I. Introduction

 

Ii. Method

The most routine usage

DatePicker

TimePicker

The month starts from 0.

 

Iii. code example

:

Code:

Fry. Activity01

1 package fry; 2 3 import com. example. datePicherDemo1.R; 4 5 import android. app. activity; 6 import android. OS. bundle; 7 import android. widget. datePicker; 8 import android. widget. datePicker. onDateChangedListener; 9 import android. widget. timePicker; 10 import android. widget. timePicker. onTimeChangedListener; 11 import android. widget. toast; 12 13 public class Activity01 extends Activity implements OnDateChangedListener, listener {14 private DatePicker datePicker1; 15 private TimePicker timePicker1; 16 @ Override17 protected void onCreate (Bundle listener) {18 // TODO Auto-generated method stub19 super. onCreate (savedInstanceState); 20 setContentView (R. layout. activity01); 21 setTitle ("time and date control test"); 22 23 datePicker1 = (DatePicker) findViewById (R. id. datePicker1); 24 timePicker1 = (TimePicker) findViewById (R. id. timePicker1); 25 // initialization date, and set the listening event 26 datePicker1.init (2017, 8, 7, this) after the date is changed ); 27 // set the time in 24-hour format 28 timePicker1.setIs24HourView (true); 29 // set the listening time 30 timePicker1.setOnTimeChangedListener (this) after the time is changed ); 31 32} 33 @ Override34 public void onDateChanged (DatePicker view, int year, int monthOfYear, 35 int dayOfMonth) {36 // TODO Auto-generated method stub37 Toast. makeText (this, "date changed to:" + year + ". "+ (monthOfYear + 1) + ". "+ dayOfMonth, Toast. LENGTH_SHORT ). show (); 38 39} 40 @ Override41 public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {42 // TODO Auto-generated method stub43 Toast. makeText (this, "time changed to:" + hourOfDay + ":" + minute, Toast. LENGTH_SHORT ). show (); 44} 45}

/DatePicherDemo1/res/layout/activity01.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" > 6  7     <DatePicker  8         android:id="@+id/datePicker1" 9         android:layout_width="match_parent"10         android:layout_height="wrap_content"11         />12     13     <TimePicker 14         android:id="@+id/timePicker1"15         android:layout_width="match_parent"16         android:layout_height="wrap_content"17         />18 19 </LinearLayout>

 

Iv. Gains

1. initialize the date and set the listener events after the date is changed.
DatePicker1.init (2017, 8, 7, this );
2. Set the time in the 24-hour format.
TimePicker1.setIs24HourView (true );
3. Set the listening event after the time is changed
TimePicker1.setOnTimeChangedListener (this );

 

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.