-
Notifications
You must be signed in to change notification settings - Fork 252
/
TimePickerFragment.txt
48 lines (37 loc) · 1.61 KB
/
TimePickerFragment.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//fragment
public class TimePickerFragment : DialogFragment,
TimePickerDialog.IOnTimeSetListener
{
// TAG can be any string of your choice.
public static readonly string TAG = "X:" + typeof(TimePickerFragment).Name.ToUpper();
// Initialize this value to prevent NullReferenceExceptions.
Action<string> _dateSelectedHandler = delegate { };
public static TimePickerFragment NewInstance(Action<string> OnTimeSet)
{
TimePickerFragment frag = new TimePickerFragment();
frag._dateSelectedHandler = OnTimeSet;
return frag;
}
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
DateTime currently = DateTime.Now;
TimePickerDialog dialog = new TimePickerDialog(Activity,this,
currently.Hour,
currently.Minute,
false);
return dialog;
}
public void OnTimeSet(TimePicker view, int hourOfDay, int minute)
{
// DateTime selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth);
// Log.Debug(TAG, selectedDate.ToLongDateString());
string time = string.Format("{0}:{1}", hourOfDay, minute.ToString().PadLeft(2, '0'));
_dateSelectedHandler(time);
}
}
//Call Fragment
TimePickerFragment frag = TimePickerFragment.NewInstance(delegate (string time)
{
button.Text = time ;
});
frag.Show(FragmentManager, TimePickerFragment.TAG);