Developing Android Apps with C # + Xamarin-Datetime picker

Source: Internet
Author: User

1. Axml


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "        Android:minwidth= "25px" android:minheight= "25px" > <linearlayout android:orientation= "Horizontal" Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:id= "@+id/linearLayout4" &G        T <textview android:text= "Service Name" android:layout_width= "400px" Android:layout_heig        ht= "Match_parent" android:id= "@+id/lblbdservicename"/> </LinearLayout> <linearlayout        android:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" Android:id= "@+id/linearlayout1" > <button android:text= "select Date" android:id= "@+      Id/btnbdchoosedate "      Android:layout_width= "154.5DP" android:layout_height= "match_parent"/> <textview android:text= "" Android:layout_width= "400px" android:layout_height= "Match_parent" Android : id= "@+id/lblbddate"/> </LinearLayout> <linearlayout android:orientation= "Horizontal" and        Roid:layout_width= "Match_parent" android:layout_height= "wrap_content" android:id= "@+id/linearLayout2" > <button android:text= "Select Time" android:id= "@+id/btnbdchoosetime" Android:layo            Ut_width= "154.5DP" android:layout_height= "match_parent"/> <textview android:text= "" Android:layout_width= "400px" android:layout_height= "match_parent" android:id= "@+id/lblbdtim E "/> </LinearLayout> <linearlayout android:orientation=" Horizontal "android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:id= "@+id/linearlayout3" > <textview android:layou T_width= "154.5DP" android:layout_height= "match_parent" android:id= "@+id/lblempty"/> <b Utton android:text= "Confirm" android:id= "@+id/btnbdconfirm" android:layout_width= "154.5DP "Android:layout_height=" match_parent "android:layout_marginright=" 320.8DP "/> </linearlayo Ut></linearlayout>



2. Activity.cs


public class Bookingdetails:activity {private TextView timedisplay;        Private Button Picktime;        private int hour;        private int minute;        const int time_dialog_id = 0;        Private TextView Datedisplay;        Private Button pickdate;        Private DateTime date;        const int date_dialog_id = 1;        Private DateTime Serverdatetime;            protected override void OnCreate (bundle bundle) {Setcontentview (Resource.Layout.BookingDetails); Base.            OnCreate (bundle);                try {var lblservicename = findviewbyid<textview> (Resource.Id.lblBdServiceName);                Lblservicename.settext ("Service 1", TextView.BufferType.Normal);                Serverdatetime = DateTime.Parse ("2015-5-22 15:30:26");                Create your application here Timedisplay = findviewbyid<textview> (Resource.Id.lblBDTime); Picktime = findviewbyid<button> (Resource.                Id.btnbdchoosetime);                ADD A click Listener to the button Picktime.click + = (o, e) = ShowDialog (time_dialog_id);                hour = Serverdatetime.hour;                minute = Serverdatetime.minute;                Updatedisplaytime ();                Capture our View elements Datedisplay = findviewbyid<textview> (Resource.Id.lblBDDate);                Pickdate = findviewbyid<button> (Resource.Id.btnBDChooseDate);                Add a Click event handler to the button Pickdate.click + = delegate {ShowDialog (date_dialog_id);};                date = Serverdatetime;                Updatedisplaydate ();                var btncfm = findviewbyid<button> (Resource.Id.btnBDConfirm); Btncfm.click + = (sender, args) + = {try {V Ar serviceName = findviewbyid<textview> (Resource.Id.lblBdServiceName).         Text;               var selectdate = findviewbyid<textview> (Resource.Id.lblBDDate).                        Text; var selecttime = findviewbyid<textview> (Resource.Id.lblBDTime).                        Text; var selecteddatetime = DateTime.Parse (string. Format ("{0} {1}", Selectdate, Selecttime)).                        ToString (); var msg = string.                        Format ("Confirm booking service ' {0} ' at {1}?", ServiceName, Selecteddatetime); This.                                Showdlgyesno (MSG, "Booking confirmation", (s, arg) + = { This.                                Showalert ("Call API book"); This.                            Gotoacticity<mainactivity> ();                             }, (s, arg) = = {//Do nothing                    });      } catch (Exception ex) {                  This. Showalert (ex.                    Message);            }                                    }; } catch (Exception ex) {this. Showalert (ex.            Message); }} private void Updatedisplaytime () {string time = string. Format ("{0}:{1}", hour, minute. ToString ().            PadLeft (2, ' 0 '));        Timedisplay.text = time; private void Updatedisplaydate () {datedisplay.text = date.        ToString ("D"); private void Timepickercallback (object sender, Timepickerdialog.timeseteventargs e) {hour = E.            Hourofday;            minute = E.minute;        Updatedisplaytime ();            } void Ondateset (object sender, Datepickerdialog.dateseteventargs e) {this.date = e.date;        Updatedisplaydate ();         } protected override Dialog Oncreatedialog (int id) {if (id = = time_dialog_id)   {return new Timepickerdialog (this, timepickercallback, hour, minute, false); } if (id = = date_dialog_id) {var dlg = new Datepickerdialog (this, Ondateset, ServerD                Atetime.year, Serverdatetime.month-1, Serverdatetime.day);            return dlg;        } return null; }    }



Developing Android Apps with C # + Xamarin-Datetime 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.