Android Development Note ___ Time Picker---timepicker

Source: Internet
Author: User

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

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.