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}.
See the Pickers
guide. |
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 | mTimeSetCallback | private final int | mInitialHourOfDay | private final int | mInitialMinute | private final boolean | mIs24HourView | private final android.widget.TimePicker.ValidationCallback | mValidationCallback |
Constructors Summary |
---|
public TimePickerDialog(android.content.Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)
this(context, 0, callBack, hourOfDay, minute, is24HourView);
| public TimePickerDialog(android.content.Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)
super(context, resolveDialogTheme(context, theme));
mTimeSetCallback = callBack;
mInitialHourOfDay = hourOfDay;
mInitialMinute = minute;
mIs24HourView = is24HourView;
final Context themeContext = getContext();
final LayoutInflater inflater = LayoutInflater.from(themeContext);
final View view = inflater.inflate(R.layout.time_picker_dialog, null);
setView(view);
setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this);
setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this);
setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);
mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
mTimePicker.setIs24HourView(mIs24HourView);
mTimePicker.setCurrentHour(mInitialHourOfDay);
mTimePicker.setCurrentMinute(mInitialMinute);
mTimePicker.setOnTimeChangedListener(this);
mTimePicker.setValidationCallback(mValidationCallback);
|
Methods Summary |
---|
public void | onClick(android.content.DialogInterface dialog, int which)
switch (which) {
case BUTTON_POSITIVE:
if (mTimeSetCallback != null) {
mTimeSetCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute());
}
break;
case BUTTON_NEGATIVE:
cancel();
break;
}
| public void | onRestoreInstanceState(android.os.Bundle savedInstanceState)
super.onRestoreInstanceState(savedInstanceState);
final int hour = savedInstanceState.getInt(HOUR);
final int minute = savedInstanceState.getInt(MINUTE);
mTimePicker.setIs24HourView(savedInstanceState.getBoolean(IS_24_HOUR));
mTimePicker.setCurrentHour(hour);
mTimePicker.setCurrentMinute(minute);
| public android.os.Bundle | onSaveInstanceState()
final 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)
/* do nothing */
| static int | resolveDialogTheme(android.content.Context context, int resid)
if (resid == 0) {
final TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.timePickerDialogTheme, outValue, true);
return outValue.resourceId;
} else {
return resid;
}
| public void | updateTime(int hourOfDay, int minuteOfHour)Sets the current time.
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minuteOfHour);
|
|