FileDocCategorySizeDatePackage
TimePickerDialog.javaAPI DocAndroid 5.1 API6526Thu Mar 12 22:22:10 GMT 2015android.app

TimePickerDialog

public class TimePickerDialog extends AlertDialog implements android.widget.TimePicker.OnTimeChangedListener, android.content.DialogInterface.OnClickListener
A 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)

param
context Parent.
param
callBack How parent is notified.
param
hourOfDay The initial hour.
param
minute The initial minute.
param
is24HourView Whether this is a 24 hour view, or AM/PM.


                             
       

                                       
              
    

                                       
      
             
                  
        this(context, 0, callBack, hourOfDay, minute, is24HourView);
    
public TimePickerDialog(android.content.Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)

param
context Parent.
param
theme the theme to apply to this dialog
param
callBack How parent is notified.
param
hourOfDay The initial hour.
param
minute The initial minute.
param
is24HourView Whether this is a 24 hour view, or AM/PM.

        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 voidonClick(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 voidonRestoreInstanceState(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.BundleonSaveInstanceState()

        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 voidonTimeChanged(android.widget.TimePicker view, int hourOfDay, int minute)

        /* do nothing */
    
static intresolveDialogTheme(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 voidupdateTime(int hourOfDay, int minuteOfHour)
Sets the current time.

param
hourOfDay The current hour within the day.
param
minuteOfHour The current minute within the hour.

        mTimePicker.setCurrentHour(hourOfDay);
        mTimePicker.setCurrentMinute(minuteOfHour);