Android Imitation iphone date time picker

Source: Internet
Author: User
Tags dateformat

Look first.
How to use
Import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.calendar;import Android.app.activity;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;public class Mainactivity extends Activity {wheelmain wheelmain; EditText Txttime;dateformat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd"); @Overridepublic void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); txttime = (EditText) Findviewbyid (R.id.txttime); Calendar calendar = Calendar.getinstance (); Txttime.settext (Calendar.get (calendar.year) + "-" + (Calendar.get ( Calendar.month) + 1) + "-" + calendar.get (calendar.day_of_month) + ""); Button Btnselecttime = (button) Findviewbyid (R.id.button1); Btnselecttime.setonclicklistener (New onclicklistEner () {@Overridepublic void OnClick (View arg0) {Layoutinflater inflater = Layoutinflater.from (mainactivity.this); Final View Timepickerview = inflater.inflate (R.layout.timepicker, NULL); Screeninfo screeninfo = new Screeninfo (mainactivity.this); wheelmain = new Wheelmain (Timepickerview, true); Wheelmain.screenheight = Screeninfo.getheight (); String time = Txttime.gettext (). toString (); Calendar calendar = Calendar.getinstance (), if (Judgedate.isdate (Time, "YYYY-MM-DD")) {try {calendar.settime ( Dateformat.parse (time));} catch (ParseException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} int year = Calendar.get (calendar.year), int month = Calendar.get (calendar.month); int day = Calendar.get (calendar.day_of_ MONTH); int h = Calendar.gettime (). getHours (); int m = Calendar.gettime (). getminutes (); Wheelmain.initdatetimepicker ( Year, month, day, H, M), new Alertdialog.builder (Mainactivity.this). Settitle ("Select Time"). Setview (Timepickerview). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (Dialoginterface dialog,int which) {Txttime.settext (Wheelmain.gettime ());}}). Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (Dialoginterface dialog, int which) {}}). Show ();}});}}
SOURCE download

Android Imitation iphone date time picker

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.