Like DatePicker, there are also timepicker.
There are also Timepickerdialog
The method used is still the same, listening to changes in the time picker.
1 PackageCom.example.alimjan.hello_world;2 3 ImportJava.util.Calendar;4 5 /**6 * Created by Alimjan on 7/15/2017.7 */8 9 ImportAndroid.app.TimePickerDialog;Ten ImportAndroid.app.TimePickerDialog.OnTimeSetListener; One ImportAndroid.content.Context; A Importandroid.content.Intent; - ImportAndroid.os.Bundle; - Importandroid.support.v7.app.AppCompatActivity; the ImportAndroid.view.View; - ImportAndroid.view.View.OnClickListener; - ImportAndroid.widget.TimePicker; - ImportAndroid.widget.TextView; + - Public classclass_5_1_2dextendsAppcompatactivityImplements + Onclicklistener, Ontimesetlistener { A at PrivateTextView tv_time; - - @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.code_5_1_2); inTv_time =(TextView) Findviewbyid (r.id.tv_time); -Findviewbyid (R.id.btn_time). Setonclicklistener ( This); to } + - @Override the Public voidOnClick (View v) { * if(V.getid () = =r.id.btn_time) { $Calendar Calendar =calendar.getinstance ();Panax NotoginsengTimepickerdialog dialog =NewTimepickerdialog ( This, This, -Calendar.get (Calendar.hour_of_day), Calendar.get (Calendar.minute),true); the dialog.show (); + } A } the + @Override - Public voidOntimeset (Timepicker view,intHourofday,intminute) { $String desc = String.Format ("The time you selected is%d minutes", Hourofday, minute); $ Tv_time.settext (DESC); - } - the Public Static voidstarthome (Context mcontext) { -Intent Intent =NewIntent (Mcontext, class_5_1_2d.class);Wuyi mcontext.startactivity (intent); the } - Wu}
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent"4 android:orientation= "vertical"5 android:padding= "10DP" >6 7 <Button8 Android:id= "@+id/btn_time"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Wrap_content" One Android:text= "Please select Time" A Android:textcolor= "@color/black" - android:textsize= "20SP" /> - the <TextView - Android:id= "@+id/tv_time" - Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" + Android:textcolor= "@color/black" - android:textsize= "17SP" /> + A </LinearLayout>
Android Development Note ___ Time Picker---timepicker