void KeepMe() { var txt = new TextView(null); txt.Text = txt.Text; var iv = new ImageView(null); var obj = iv.Drawable; var prog = new ProgressBar(null); prog.Progress = prog.Progress; var cb = new RadioButton(null); cb.Checked = cb.Checked; var np = new NumberPicker(null); np.Value = np.Value; var rb = new RatingBar(null); rb.Rating = rb.Rating; var cv = new CalendarView(null); cv.Date = cv.Date; var th = new TabHost(null); th.CurrentTab = th.CurrentTab; var tp = new TimePicker(null); tp.CurrentHour = tp.CurrentHour; tp.CurrentMinute = tp.CurrentMinute; }
public void OnTimeSet(Android.Widget.TimePicker view, int hourOfDay, int minute) { var time = new TimeSpan(hourOfDay, minute, 0); this.Element.SetValue(Xamarin.Forms.TimePicker.TimeProperty, time); Control.Text = time.ToString(@"hh\:mm"); }
protected override void OnElementChanged(ElementChangedEventArgs <DateTimePickerView> e) { base.OnElementChanged(e); if (e.NewElement == null) { return; } var linearLayout = new LinearLayout(this.Context); var datePicker = new Android.Widget.DatePicker(this.Context); Calendar calendar = Calendar.Instance; datePicker.MinDate = GetDateFromDateTime(Element.MinimumDateTime); datePicker.MaxDate = GetDateFromDateTime(Element.MaximumDateTime); datePicker.Init(calendar.Get(CalendarField.Year), calendar.Get(CalendarField.Month), calendar.Get(CalendarField.DayOfMonth), this); var datePickerParams = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent, 1); linearLayout.AddView(datePicker, datePickerParams); if (Element.PickerMode == PickerMode.DateTime) { var timePicker = new Android.Widget.TimePicker(this.Context); var timePickerParams = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent, 1); linearLayout.AddView(timePicker, timePickerParams); } SetNativeControl(linearLayout); }
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate (Resource.Layout.fragment_time_picker, container, false); timePicker = (TimePicker)view.FindViewById (Resource.Id.time_picker_alarm); var buttonOk = (Button)view.FindViewById (Resource.Id.button_ok_time_picker); buttonOk.Click += delegate { DateTime alarmTime = alarmUtil.GetNextAlarmTime (timePicker.Hour, timePicker.Minute); Alarm alarm = alarmStorage.SaveAlarm (alarmTime.Year, alarmTime.Month, alarmTime.Day, alarmTime.Hour, alarmTime.Minute); string alarmSavedString = Activity.GetString (Resource.String.alarm_saved, alarm.Hour, alarm.Minute); Toast.MakeText (Activity, alarmSavedString, ToastLength.Short).Show (); if (alarmAddListener != null) alarmAddListener.OnAlarmAdded (alarm); Dismiss (); }; var buttonCancel = (Button)view.FindViewById (Resource.Id.button_cancel_time_picker); buttonCancel.Click += delegate { Dismiss (); }; return view; }
public override Dialog OnCreateDialog (Bundle savedInstanceState) { var view = LayoutInflater.From (Activity) .Inflate (Resource.Layout.ChangeTimeEntryStartTimeDialogFragment, null); tabsRadioButton = view.FindViewById<RadioGroup> (Resource.Id.TabsRadioGroup); timeTabRadioButton = view.FindViewById<RadioButton> (Resource.Id.TimeTabRadioButton).SetFont (Font.Roboto); dateTabRadioButton = view.FindViewById<RadioButton> (Resource.Id.DateTabRadioButton).SetFont (Font.Roboto); timePicker = view.FindViewById<TimePicker> (Resource.Id.TimePicker); datePicker = view.FindViewById<DatePicker> (Resource.Id.DatePicker); // WORKAROUND: Without these two lines the app will crash on rotation. See #258. timePicker.SaveFromParentEnabled = false; timePicker.SaveEnabled = true; tabsRadioButton.CheckedChange += OnTabsRadioGroupCheckedChange; SetupViews (); Rebind (); var dia = new AlertDialog.Builder (Activity) .SetTitle (DialogTitle) .SetView (view) .SetPositiveButton (Resource.String.ChangeTimeEntryStartTimeDialogOk, OnOkButtonClicked) .Create (); return dia; }
public void OnTimeChanged (TimePicker view, int hourOfDay, int minute) { var calendar = Calendar.Instance; calendar.Set(CalendarField.HourOfDay,timePicker.CurrentHour.IntValue()); calendar.Set (CalendarField.Minute, timePicker.CurrentMinute.IntValue()); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); dateTime = sdf.Format (calendar.Time); }
void TimePickerDialog.IOnTimeSetListener.OnTimeSet(ATimePicker view, int hourOfDay, int minute) { ((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); ((IElementController)Element).SetValueFromRenderer(TimePicker.TimeProperty, new TimeSpan(hourOfDay, minute, 0)); Control.ClearFocus(); _dialog = null; }
public void OnTimeSet(Android.Widget.TimePicker view, int hourOfDay, int minute) { var currentTime = DateTime.Now; var selectedTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, hourOfDay, minute, 0); Log.Debug(Tag, selectedTime.ToLongTimeString()); this.timeSelectedHandler(selectedTime); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { EventHandler handler = ValueChanged; if (handler != null) { handler(this, null); } }
public void OnTimeChanged(TimePicker view, int hour, int minute) { mDate = new DateTime(mDate.Year, mDate.Month, mDate.Day, hour, minute, 0); Arguments.PutInt(EXTRA_HOUR, mDate.Hour); Arguments.PutInt(EXTRA_MINUTE, mDate.Minute); Console.WriteLine("Time Changed: {0}", mDate.ToLongTimeString()); }
//Fired whenever the TimePicker changes value. public void OnTimeSet(Android.Widget.TimePicker view, int hourOfDay, int minute) { //change Element value for binding purposes (also causes triggering of OnElementPropertyChanged) var timeSpan = new TimeSpan(hourOfDay, minute, 0); //Though we could set Element values like this: this.Element.SetValue(Xamarin.Forms.TimePicker.TimeProperty, timeSpan); //And virtually alle simple examples works like that, it is frowned upon as it can break OneWay-bindings. //An alternative was therefore implemented in later Xamarin versions which is especially designed for this situation: ((IElementController)Element).SetValueFromRenderer(Xamarin.Forms.TimePicker.TimeProperty, timeSpan); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Gets the layout, and all the relevant views it contains. Layout = inflater.Inflate(Resource.Layout.editEventTimeLayout, null); Picker = Layout.FindViewById<TimePicker>(Resource.Id.timepicker); // Sets the selected time of the timepicker to be either, the time contained in // the activities Intent or DateTime.Now. Picker.CurrentHour = (Java.Lang.Integer)Activity.Intent.GetIntExtra("date hour", DateTime.Now.Hour); Picker.CurrentMinute = (Java.Lang.Integer)Activity.Intent.GetIntExtra("date minutte", DateTime.Now.Minute); return Layout; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); durationSpinner = FindViewById<Spinner>(Resource.Id.duration_spinner); var adapter = ArrayAdapter.CreateFromResource( this, Resource.Array.durations, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); durationSpinner.Adapter = adapter; datePicker = FindViewById<DatePicker>(Resource.Id.date_picker); timePicker = FindViewById<TimePicker>(Resource.Id.time_picker); var saveEvent = FindViewById<Button>(Resource.Id.create_event); saveEvent.Click += async (sender, args) => { App.NewEventViewModel.Date = new DateTime(datePicker.DateTime.Year, datePicker.DateTime.Month, datePicker.DateTime.Day, timePicker.CurrentHour.IntValue(), timePicker.CurrentMinute.IntValue(), 0).ToLocalTime(); switch(durationSpinner.SelectedItemPosition) { case 0: App.NewEventViewModel.DurationMinutes = 5; break; case 1: App.NewEventViewModel.DurationMinutes = 10; break; case 2: App.NewEventViewModel.DurationMinutes = 15; break; case 3: App.NewEventViewModel.DurationMinutes = 30; break; case 4: App.NewEventViewModel.DurationMinutes = 45; break; case 5: App.NewEventViewModel.DurationMinutes = 60; break; default: App.NewEventViewModel.DurationMinutes = 5; break; } AndroidHUD.AndHUD.Shared.Show(this, "Adding Event..."); await App.NewEventViewModel.AddEvent(); AndroidHUD.AndHUD.Shared.Dismiss(this); Finish(); }; }
void TimePickerDialog.IOnTimeSetListener.OnTimeSet(ATimePicker view, int hourOfDay, int minute) { ElementController.SetValueFromRenderer(TimePicker.TimeProperty, new TimeSpan(hourOfDay, minute, 0)); ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); if (Forms.IsLollipopOrNewer) { _dialog.CancelEvent -= OnCancelButtonClicked; } _dialog = null; }
private void InitTimePicker(TimePicker _timePicker) { Calendar calendar = Calendar.Instance; if (!string.IsNullOrEmpty (initTime)) { var time = initTime.Split (new string[]{ ":" },StringSplitOptions.RemoveEmptyEntries); var hour =Integer.ValueOf(time[0]); var minute = Integer.ValueOf (time [1]); _timePicker.CurrentHour = hour; _timePicker.CurrentMinute = minute; } else { _timePicker.CurrentHour = Integer.ValueOf(calendar.Get (CalendarField.HourOfDay)); _timePicker.CurrentMinute = Integer.ValueOf(calendar.Get (CalendarField.Minute)); } }
protected override void OnCreate (Bundle savedInstanceState) { RequestWindowFeature (WindowFeatures.NoTitle); base.OnCreate (savedInstanceState); SetContentView (Resource.Layout.alarm_controller); btnSet = FindViewById<Button>(Resource.Id.btnSet); btnRandom = FindViewById<Button>(Resource.Id.btnRandom); timePicker = FindViewById<TimePicker>(Resource.Id.timePicker); btnTheme= FindViewById<Button>(Resource.Id.btnTheme); timePicker.SetIs24HourView ((Java.Lang.Boolean)true); btnSet.Click += btnSet_Click; btnRandom.Click += btnRandom_Click; btnTheme.Click += btnTheme_Click; }
protected override void OnLoaded() { base.OnLoaded(); _nativePicker = this.FindFirstChild <Android.Widget.TimePicker>(); if (_nativePicker != null) { //By settings DescendantFocusability to BlockDescendants it disables the possibility to use the keyboard to modify time which was causing issues in 4.4 _nativePicker.DescendantFocusability = Android.Views.DescendantFocusability.BlockDescendants; SetTimeOnNativePicker(Time); OnClockIdentifierChangedPartialNative(null, ClockIdentifier); } else if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"No native TimePicker was found in the visual hierarchy."); } }
/** * Setting wrap_content on a ViewPager's layout_height in XML * doesn't seem to be recognized and the ViewPager will fill the * height of the screen regardless. We'll force the ViewPager to * have the same height as its immediate child. */ protected override void OnMeasure (int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure (widthMeasureSpec, heightMeasureSpec); if (ChildCount > 0) { View childView = GetChildAt(0); if (childView != null) { childView.Measure(widthMeasureSpec, heightMeasureSpec); int height = childView.MeasuredHeight; SetMeasuredDimension(MeasuredWidth, height); LayoutParameters.Height = height; } } _datePicker = (DatePicker) FindViewById(Resource.Id.datePicker); _timePicker = (TimePicker) FindViewById(Resource.Id.timePicker); }
public static Dialog Build(Activity activity, TimePromptConfig config) { var picker = new TimePicker(activity); var builder = new AlertDialog .Builder(activity) .SetCancelable(false) .SetTitle(config.Title) .SetView(picker); if (config.SelectedTime != null) { picker.CurrentHour = new Integer(config.SelectedTime.Value.Hours); picker.CurrentMinute = new Integer(config.SelectedTime.Value.Minutes); } var is24Hour = config.Use24HourClock ?? DateFormat.Is24HourFormat (activity); picker.SetIs24HourView(new Java.Lang.Boolean(is24Hour)); if (config.IsCancellable) { builder.SetNegativeButton( config.CancelText, (sender, args) => { var ts = new TimeSpan(0, picker.CurrentHour.IntValue(), picker.CurrentMinute.IntValue(), 0); config.OnAction?.Invoke(new TimePromptResult(false, ts)); } ); } builder.SetPositiveButton( config.OkText, (sender, args) => { var ts = new TimeSpan(0, picker.CurrentHour.IntValue(), picker.CurrentMinute.IntValue(), 0); config.OnAction?.Invoke(new TimePromptResult(true, ts)); } ); return builder.Show(); }
public void TimePickDialogShow(EditText edit_inputTime) { var timepickerlayout = (LinearLayout) activity.LayoutInflater.Inflate (Resource.Layout.commontimepickerlayout, null); timePicker = (TimePicker) timepickerlayout.FindViewById<TimePicker>(Resource.Id.timepicker); InitTimePicker (timePicker); timePicker.SetIs24HourView(Java.Lang.Boolean.ValueOf(true)); timePicker.SetOnTimeChangedListener(this); var builder = new AlertDialog.Builder (activity).SetView(timepickerlayout); builder.SetPositiveButton ("设置", (sender, e) => { dialog.Dismiss(); edit_inputTime.Text = dateTime; }); builder.SetNegativeButton ("取消", (sender, e) => { dialog.Dismiss(); }); dialog= builder.Create (); dialog.Show(); OnTimeChanged (null,0,0); }
public override void OnTimeChanged(Android.Widget.TimePicker view, int hourOfDay, int minute) { base.OnTimeChanged(view, hourOfDay, minute); if (_ignoreEvent) { return; } if (minute % TimePickerInterval != 0) { int minuteFloor = minute - (minute % TimePickerInterval); minute = minuteFloor + (minute == minuteFloor + 1 ? TimePickerInterval : 0); if (minute == 60) { minute = 0; } _ignoreEvent = true; view.CurrentMinute = (Java.Lang.Integer)minute; _ignoreEvent = false; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.podajGodzine); Zmienne.czasPicia = 0; Zmienne.czas1 = 0; // Create your application here //godzina pobierana z telefonu g1 = DateTime.Now.Hour; m1 = DateTime.Now.Minute; //suma godzin i minut pobranych z telefonu Zmienne.czas1 = g1 + (m1 / 60); //jak wywo³uje siê zegar w nowej metodzie to dziala liczenie, ale zegar jest am/pm zegar = FindViewById<TimePicker>(Resource.Id.timePicker1); zegar.SetIs24HourView(Java.Lang.Boolean.True); Button buttonPodajGodzine = FindViewById<Button>(Resource.Id.buttonPodajGodzine); buttonPodajGodzine.Click += ButtonPodajGodzine_Click; }
public override Android.Views.View OnCreateView(Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Bundle savedInstanceState) { int theme = Arguments.GetInt ("theme"); int initialHour = Arguments.GetInt ("hour"); int initialMinute = Arguments.GetInt ("minute"); bool isClientSpecified24HourTime = Arguments.GetBoolean ("isClientSpecified24HourTime"); bool is24HourTime = Arguments.GetBoolean ("is24HourTime"); Context contextThemeWrapper = new ContextThemeWrapper ( Activity, theme == SlideDateTimePicker.HOLO_DARK ? Android.Resource.Style.ThemeHolo : Android.Resource.Style.ThemeHoloLight); LayoutInflater localInflater = inflater.CloneInContext (contextThemeWrapper); View v = localInflater.Inflate (Resource.Layout.Fragment_Time, container, false); mTimePicker = v.FindViewById<TimePicker> (Resource.Id.timePicker); mTimePicker.DescendantFocusability = DescendantFocusability.BlockDescendants; mTimePicker.SetOnTimeChangedListener (this); if (isClientSpecified24HourTime) { mTimePicker.SetIs24HourView(new Java.Lang.Boolean(is24HourTime)); } else { mTimePicker.SetIs24HourView (new Java.Lang.Boolean (DateFormat.Is24HourFormat (TargetFragment.Activity))); } mTimePicker.CurrentHour = new Java.Lang.Integer(initialHour); mTimePicker.CurrentMinute = new Java.Lang.Integer(initialMinute); if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich && Build.VERSION.SdkInt <= BuildVersionCodes.IceCreamSandwichMr1) { FixTimePickerBug18982 (); } return v; }
public void OnTimeSet(Android.Widget.TimePicker view, int hourOfDay, int minute) { timeSpan = new TimeSpan(hourOfDay, minute, 0); setTime(timeSpan); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { mCallBack.OnTimeChanged (hourOfDay, minute); }
public void OnTimeSet(TimePicker view, int hourOfDay, int minute) { var date = new DateTime(10,10,10,hourOfDay, minute, 0); var txt = ListActionHelper.filterView.FindViewById<TextView>(textView); var formattedTime = date.ToString("hh:mm tt"); txt.Text = formattedTime; }
public void OnTimeSet (TimePicker view, int hourOfDay, int minute) { if (_controlClicked == "edStartTelefon") { _edStartTelefon.Text = hourOfDay.ToString ("00") + ":" + minute.ToString ("00"); } else if (_controlClicked == "edZeit") { _edZeit.Text = hourOfDay.ToString ("00") + ":" + minute.ToString ("00"); } else if (_controlClicked == "edDauerTelefon") { _edDauerTelefon.Text = hourOfDay.ToString ("00") + ":" + minute.ToString ("00"); } }
public void OnTimeSet(TimePicker view, int hourOfDay, int minute) { alarmList [currentAlarmPosition].AlarmDateTime = new DateTime (1970, 1, 1, hourOfDay, minute, 0); ViewModel.Update (alarmList [currentAlarmPosition]); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { TimeChanged.Invoke(view, new TimeChangedEventArgs(hourOfDay, minute)); }
protected override void OnElementChanged(ElementChangedEventArgs <DateTimePicker> e) { base.OnElementChanged(e); if (e.OldElement != null || this.Element == null) { return; } MainActivity activity = Forms.Context as MainActivity; LayoutInflater inflater = (LayoutInflater)(activity.LayoutInflater); Android.Views.View dateLayout = Android.Views.View.Inflate(activity, Resource.Layout.DateTimePicker, null); Android.Widget.Button date_button = dateLayout.FindViewById <Android.Widget.Button>(Resource.Id.date_button); Android.Widget.Button time_button = dateLayout.FindViewById <Android.Widget.Button>(Resource.Id.time_button); datePicker = dateLayout.FindViewById <Android.Widget.DatePicker>(Resource.Id.date_picker); timePicker = dateLayout.FindViewById <Android.Widget.TimePicker>(Resource.Id.time_picker); date_button.Click += Date_button_Click; time_button.Click += TimePicker_Click; SetNativeControl(dateLayout); //Android.Views.View dateLayout = inflater.Inflate(Resource.Layout.DateTimePicker, null, false) as LinearLayout; //AlertDialog alertDialog = new AlertDialog.Builder(activity).Create(); //Android.Widget.DatePicker datePicker = dateLayout.FindViewById<Android.Widget.DatePicker>(Resource.Id.date_picker); //Android.Widget.TimePicker timePicker = dateLayout.FindViewById<Android.Widget.TimePicker>(Resource.Id.time_picker); //Calendar calendar = new GregorianCalendar(datePicker.Year, // datePicker.Month, // datePicker.DayOfMonth, // timePicker.Hour, // timePicker.Minute); //alertDialog.SetView(dateLayout); //SetNativeControl(alertDialog.); //datePicker = new Android.Widget.DatePicker(this.Context); //this.SetNativeControl(datePicker); //MainActivity activity = Forms.Context as MainActivity; //DatePickerFragment frag = DatePickerFragment.NewInstance(delegate (DateTime time) //{ // //_dateDisplay.Text = time.ToLongDateString(); //}); //frag.Show(activity.FragmentManager, DatePickerFragment.TAG); }
protected override void OnCreate(Bundle icicle) { base.OnCreate(icicle); Window w = Window; w.RequestFeature (WindowFeatures.LeftIcon); SetContentView(Resource.Layout.push_preferences_dialog); pushEnabled = (CheckBox) FindViewById(Resource.Id.push_enabled); soundEnabled = (CheckBox) FindViewById(Resource.Id.sound_enabled); vibrateEnabled = (CheckBox) FindViewById(Resource.Id.vibrate_enabled); quietTimeEnabled = (CheckBox) FindViewById(Resource.Id.quiet_time_enabled); locationEnabled = (CheckBox) FindViewById(Resource.Id.location_enabled); backgroundLocationEnabled = (CheckBox) FindViewById(Resource.Id.background_location_enabled); foregroundLocationEnabled = (CheckBox) FindViewById(Resource.Id.foreground_location_enabled); locationEnabledLabel = (TextView) FindViewById(Resource.Id.location_enabled_label); backgroundLocationEnabledLabel = (TextView) FindViewById(Resource.Id.background_location_enabled_label); foregroundLocationEnabledLabel = (TextView) FindViewById(Resource.Id.foreground_location_enabled_label); startTime = (TimePicker) FindViewById(Resource.Id.start_time); endTime = (TimePicker) FindViewById(Resource.Id.end_time); startTime.SetIs24HourView (new Java.Lang.Boolean (DateFormat.Is24HourFormat(this))); endTime.SetIs24HourView (new Java.Lang.Boolean (DateFormat.Is24HourFormat(this))); pushEnabled.Click += (v, e) => { PushSettingsActive(((CheckBox) v).Checked); }; quietTimeEnabled.Click += (v, e) => { QuietTimeSettingsActive(((CheckBox)v).Checked); }; locationEnabled.Click += (v, e) => { BackgroundLocationActive(((CheckBox)v).Checked); ForegroundLocationActive(((CheckBox)v).Checked); }; }
private void OnTimePickerTimeChanged (object sender, TimePicker.TimeChangedEventArgs e) { Rebind (); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { ValueChanged?.Invoke(this, null); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { timePicker.InternalSetValueAndRaiseChanged(new TimeSpan(hourOfDay, minute, 0)); }
// For some reason this method never triggeres public void OnTimeChanged(Android.Widget.TimePicker view, int hourOfDay, int minute) { // assign values to (Element as StyledDateTimePicker).SelectedDateTime here }
public override void SetView(View view) { _picker = (Android.Widget.TimePicker)view; base.SetView(_picker); }
public void OnTimeChanged(TimePicker view, int hourOfDay, int minute) { EventHandler handler = ValueChanged; handler?.Invoke(this, null); }
public void OnTimeSet(TimePicker view, int hourOfDay, int minute) { string temp = minute.ToString(); if(minute < 10) temp = "0" + minute; t.Text = hourOfDay + ":" + temp; if(t2 != null) t2.Text = (hourOfDay+2) + ":" + temp; }
public void OnTimeSet(TimePicker view, int hourOfDay, int minute) { mTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hourOfDay, minute, 0); mTimeTextView.Text = $"Czas: {mTime.ToString("HH:mm")}"; }
void TimePicker.IOnTimeChangedListener.OnTimeChanged (TimePicker view, int hourOfDay, int minute) { _callback.OnTimeChanged(hourOfDay, minute); }
public void OnTimeSet(TimePicker view, int hour, int minute) { // formats hours to 12hr time string something; if (hour == 0) { hour = hour + 12; something = "AM"; } else if (hour > 12) { hour = hour - 12; something = "PM"; } else { something = "AM"; } //corrects minutes to the correct format 0-> 00 etc. string formattedMinutes; switch (minute) { case 0: formattedMinutes = "00"; break; case 1: formattedMinutes = "01"; break; case 2: formattedMinutes = "02"; break; case 3: formattedMinutes = "03"; break; case 4: formattedMinutes = "04"; break; case 5: formattedMinutes = "05"; break; case 6: formattedMinutes = "06"; break; case 7: formattedMinutes = "07"; break; case 8: formattedMinutes = "08"; break; case 9: formattedMinutes = "09"; break; default: formattedMinutes = minute.ToString (); break; } string timeString = string.Format ("{0}:{1} {2}", hour, formattedMinutes, something); View.FindViewById<EditText> (Resource.Id.time).Text = timeString; }
/** * Create and return the user interface view for this fragment. */ public override Android.Views.View OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Bundle savedInstanceState) { int theme = Arguments.GetInt("theme"); int initialHour = Arguments.GetInt("hour"); int initialMinute = Arguments.GetInt("minute"); bool isClientSpecified24HourTime = Arguments.GetBoolean("isClientSpecified24HourTime"); bool is24HourTime = Arguments.GetBoolean("is24HourTime"); // Unless we inflate using a cloned inflater with a Holo theme, // on Lollipop devices the TimePicker will be the new-style // radial TimePicker, which is not what we want. So we will // clone the inflater that we're given but with our specified // theme, then inflate the layout with this new inflater. Context contextThemeWrapper = new ContextThemeWrapper( Activity,theme == SlideDateTimePicker._holoDark ?Android.Resource.Style.ThemeHolo : Android.Resource.Style.ThemeHoloLight); LayoutInflater localInflater = inflater.CloneInContext(contextThemeWrapper); View view = localInflater.Inflate(Resource.Layout.FragmentTimeLayout, container, false); _timePicker = (TimePicker) view.FindViewById(Resource.Id.timePicker); // block keyboard popping up on touch _timePicker.DescendantFocusability=DescendantFocusability.BlockDescendants; _timePicker.SetOnTimeChangedListener (this); // If the client specifies a 24-hour time format, set it on // the TimePicker. if (isClientSpecified24HourTime) { _timePicker.SetIs24HourView((Boolean)is24HourTime); } else { // If the client does not specify a 24-hour time format, use the // device default. _timePicker.SetIs24HourView((Boolean)DateFormat.Is24HourFormat(TargetFragment.Activity)); } _timePicker.CurrentHour=(Integer)initialHour; _timePicker.CurrentMinute=(Integer)initialMinute; // Fix for the bug where a TimePicker's onTimeChanged() is not called when // the user toggles the AM/PM button. Only applies to 4.0.0 and 4.0.3. if ((int)Build.VERSION.SdkInt >= 14 && (int)Build.VERSION.SdkInt <= 15) { FixTimePickerBug18982(); } return view; }