public TimePickerDialog( Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, theme); mCallback = callBack; mInitialHourOfDay = hourOfDay; mInitialMinute = minute; mIs24HourView = is24HourView; setIcon(0); setTitle(R.string.time_picker_dialog_title); Context themeContext = getContext(); setButton(DialogInterface.BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this); setButton( DialogInterface.BUTTON_NEGATIVE, themeContext.getText(android.R.string.cancel), (OnClickListener) null); View view = LayoutInflater.inflate(themeContext, R.layout.time_picker_dialog); setView(view); mTimePicker = (TimePicker) view.findViewById(R.id.timePicker); mTimePicker.setIs24HourView(mIs24HourView); mTimePicker.setCurrentHour(mInitialHourOfDay); mTimePicker.setCurrentMinute(mInitialMinute); mTimePicker.setOnTimeChangedListener(this); }
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); int hour = savedInstanceState.getInt(TimePickerDialog.HOUR); int minute = savedInstanceState.getInt(TimePickerDialog.MINUTE); mTimePicker.setIs24HourView(savedInstanceState.getBoolean(TimePickerDialog.IS_24_HOUR)); mTimePicker.setCurrentHour(hour); mTimePicker.setCurrentMinute(minute); }