TimePickerDialog changed after Android 4.1.1, and there is an error about canceling both TimePickerDialog and DatePickerDialog. Read here first. By default, you do not need to set a positive and negative button. TimePickerDialog and DatePickerDialog handle them for you. Therefore, if this cancellation problem is not important to you, remove the positive and negative button settings. If you delete them in both versions, if the user clicks OK, you will call your onTimeSet method.
But I recommend until this error is fixed using a custom AlertDialog with TimePicker widgets;
final TimePicker timePicker = new TimePicker(this); timePicker.setIs24HourView(true); timePicker.setCurrentHour(20); timePicker.setCurrentMinute(15); new AlertDialog.Builder(this) .setTitle("Test") .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("Picker", timePicker.getCurrentHour() + ":" + timePicker.getCurrentMinute()); } }) .setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("Picker", "Cancelled!"); } }).setView(timePicker).show();
cirit source share