TimePickerDialogpublic class TimePickerDialog extends AlertDialog implements android.widget.TimePicker.OnTimeChangedListener, android.content.DialogInterface.OnClickListenerA dialog that prompts the user for the time of day using a {@link TimePicker}. |
Fields Summary |
---|
private static final String | HOUR | private static final String | MINUTE | private static final String | IS_24_HOUR | private final android.widget.TimePicker | mTimePicker | private final OnTimeSetListener | mCallback | private final Calendar | mCalendar | private final DateFormat | mDateFormat | int | mInitialHourOfDay | int | mInitialMinute | boolean | mIs24HourView |
Constructors Summary |
---|
public TimePickerDialog(android.content.Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)
this(context, com.android.internal.R.style.Theme_Dialog_Alert,
callBack, hourOfDay, minute, is24HourView);
| public TimePickerDialog(android.content.Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)
super(context, theme);
mCallback = callBack;
mInitialHourOfDay = hourOfDay;
mInitialMinute = minute;
mIs24HourView = is24HourView;
mDateFormat = DateFormat.getTimeFormat(context);
mCalendar = Calendar.getInstance();
updateTitle(mInitialHourOfDay, mInitialMinute);
setButton(context.getText(R.string.date_time_set), this);
setButton2(context.getText(R.string.cancel), (OnClickListener) null);
setIcon(R.drawable.ic_dialog_time);
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.time_picker_dialog, null);
setView(view);
mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
// initialize state
mTimePicker.setCurrentHour(mInitialHourOfDay);
mTimePicker.setCurrentMinute(mInitialMinute);
mTimePicker.setIs24HourView(mIs24HourView);
mTimePicker.setOnTimeChangedListener(this);
|
Methods Summary |
---|
public void | onClick(android.content.DialogInterface dialog, int which)
if (mCallback != null) {
mTimePicker.clearFocus();
mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute());
}
| public void | onRestoreInstanceState(android.os.Bundle savedInstanceState)
super.onRestoreInstanceState(savedInstanceState);
int hour = savedInstanceState.getInt(HOUR);
int minute = savedInstanceState.getInt(MINUTE);
mTimePicker.setCurrentHour(hour);
mTimePicker.setCurrentMinute(minute);
mTimePicker.setIs24HourView(savedInstanceState.getBoolean(IS_24_HOUR));
mTimePicker.setOnTimeChangedListener(this);
updateTitle(hour, minute);
| public android.os.Bundle | onSaveInstanceState()
Bundle state = super.onSaveInstanceState();
state.putInt(HOUR, mTimePicker.getCurrentHour());
state.putInt(MINUTE, mTimePicker.getCurrentMinute());
state.putBoolean(IS_24_HOUR, mTimePicker.is24HourView());
return state;
| public void | onTimeChanged(android.widget.TimePicker view, int hourOfDay, int minute)
updateTitle(hourOfDay, minute);
| public void | updateTime(int hourOfDay, int minutOfHour)
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minutOfHour);
| private void | updateTitle(int hour, int minute)
mCalendar.set(Calendar.HOUR_OF_DAY, hour);
mCalendar.set(Calendar.MINUTE, minute);
setTitle(mDateFormat.format(mCalendar.getTime()));
|
|