Time Picker (Timepicker)
Java.lang.Object;
Android.view.View;
Android.view.ViewGroup;
Android.widget.FrameLayout;
Android.widget.TimePicker;
Timepicker class method
Timepick Example
Complete project: http://download.csdn.net/detail/sweetloveft/9410965
The following procedure is mainly to learn the use of Timepicker, do not use the Calendar is the same as the same, need to pay attention to the 24-hour time problem.
1.mainactivity.java
Package Com.sweetlover.activity;import Com.sweetlover.timepickerdemo.r;import Android.app.activity;import Android.os.bundle;import Android.widget.textview;import Android.widget.timepicker;import Android.widget.timepicker.ontimechangedlistener;public class Mainactivity extends Activity {private TextView TextView = null;private Timepicker timepicker = null;private int curhour = 8, Curminute =: @Overrideprotected void OnCreate (Bundl E savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); TextView = (TextView) Findviewbyid (r.id.textview1); timepicker = (Timepicker) Findviewbyid ( R.id.timepicker1); Timepicker.setis24hourview (false); Timepicker.setontimechangedlistener (New TimeChangedListener ());} Private class Timechangedlistener implements Ontimechangedlistener {@Overridepublic void ontimechanged (Timepicker view , int hourofday, int minute) {//TODO auto-generated Method stubcurhour = Hourofday;curminute = Minute;textview.SetText ("Current time:" + Curhour + "when" + Curminute + "Min");}}}
2.activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:padding= "30DP" android:orientation= "vertical" > <timepicker android:id= "@+id/timepicker1" Android : layout_width= "wrap_content" android:layout_height= "wrap_content"/> <textview android:id= "@+ Id/textview1 " android:layout_width=" wrap_content " android:layout_height=" Wrap_content " android: layout_gravity= "center" android:layout_margintop= "30DP" android:textappearance= "? android:attr/ Textappearancemedium "/></linearlayout>
3.androidmanifest.xml
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= " Com.sweetlover.timepickerdemo " android:versioncode=" 1 " android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/>" <application android: Allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android: Theme= "@style/apptheme" > <activity android:name= "com.sweetlover.activity.MainActivity" > < intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> </ Application></manifest>
Read Android from Getting started to mastering (14)--Time picker