public static class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.set(0, 0, 0, hourOfDay, minute);
textView.setText((String) DateFormat.format("hh:mm aaa", calendar));
}
}
//For showing the dialog put below two lines where you want to call
TimePickerFragment timePickerFragment = new TimePickerFragment();
timePickerFragment.show(getSupportFragmentManager(), "TimePicker");
非常感謝您的快速響應。我沒有從文檔中獲得。 – JDM 2010-04-17 21:38:20
是的,它不是真的在文檔中::-) – CommonsWare 2010-04-17 22:03:34
您可以通過以下方式獲得用戶的首選24小時設置:DateFormat.is24HourFormat(context); – 2011-09-27 15:50:25