I have an activity - TimePickerActivity - which creates a TimePickerDialog. I have a onTimeSetListener which responds to the Set button at the end of which it calls finish(
TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
//ok button clicked
}
};
Calendar c = Calendar.getInstance();
int now_hour = c.get(Calendar.HOUR_OF_DAY);
int now_minutes = c.get(Calendar.MINUTE);
final TimePickerDialog timePickerDialog = new TimePickerDialog(this, timePickerListener, now_hour, now_minutes + 1, false);
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//cancel button clicked
}
});
timePickerDialog.show();