I'm trying to set a 10 minute interval in the android DialogFragment
(suggested by google), but I really can't find a way to do it.
Here is the fragment class wich shows the dialog:
public class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String realMinute= "";
switch (minute) {
case 1:
realMinute = "01";
break;
case 2:
realMinute = "02";
break;
case 3:
realMinute = "03";
break;
case 4:
realMinute = "04";
break;
case 5:
realMinute = "05";
break;
case 6:
realMinute = "06";
break;
case 7:
realMinute = "07";
break;
case 8:
realMinute = "08";
break;
case 9:
realMinute = "09";
break;
default:
realMinute = String.valueOf(minute);
break;
}
final String selectedDate = String.valueOf(hourOfDay) + ":" + realMinute;
EditText selectedTimeTxt = (EditText) getActivity().findViewById(R.id.selectedTime);
selectedTimeTxt.setText(selectedDate);
}
Everything works as expected, but what I need is to allow the user to pick only intervals of 10 minutes - for example 1:10, 1:20, 1:30, 1:40 etc...
Is it possible to modify it, or extend it somehow in order to fit my needs? I know that I'm missing a basic point here, but as a newbie I'm not able to spot it.
EDIT
Here my views are: