I have a custom dialog with user timepicker and datepicker. I want to set up a temporary collection of minute counts [0, 15, 30, 45], i.e. Intervals of 15 minutes.
Now I see several solutions, but none of them reflects the fact that the next and previous minutes will be displayed in the user interface when -1 and +1 minutes of the selected minute will be displayed to the user, for example, 29, 30, 31.
In addition, I do not understand how I attach my custom timepicker to activity - for this I do not need the customerTimePicker xml component?
So, briefly - can I set my own time peak or create my own XML class and class?
What I have at present
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timePicker_fixture"
android:layout_weight="1" />
Activities
TimePicker timePicker_fixture = (TimePicker) dialog.findViewById(R.id.timePicker_fixture);
timePicker_fixture.setIs24HourView(true);
( - xml ?)
public class CustomTimePickerDialog extends TimePickerDialog {
private final static int TIME_PICKER_INTERVAL = 15;
private TimePicker timePicker;
private final OnTimeSetListener callback;
public CustomTimePickerDialog(Context context, OnTimeSetListener callBack,
int hourOfDay, int minute, boolean is24HourView) {
super(context, TimePickerDialog.THEME_HOLO_LIGHT, callBack, hourOfDay, minute / TIME_PICKER_INTERVAL,
is24HourView);
this.callback = callBack;
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null && timePicker != null) {
timePicker.clearFocus();
callback.onTimeSet(timePicker, timePicker.getCurrentHour(),
timePicker.getCurrentMinute() * TIME_PICKER_INTERVAL);
}
}
@Override
protected void onStop() {
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
try {
Class<?> classForid = Class.forName("com.android.internal.R$id");
Field timePickerField = classForid.getField("timePicker");
this.timePicker = (TimePicker) findViewById(timePickerField
.getInt(null));
Field field = classForid.getField("minute");
NumberPicker mMinuteSpinner = (NumberPicker) timePicker
.findViewById(field.getInt(null));
mMinuteSpinner.setMinValue(0);
mMinuteSpinner.setMaxValue((60 / TIME_PICKER_INTERVAL) - 1);
List<String> displayedValues = new ArrayList<String>();
for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) {
displayedValues.add(String.format("%02d", i));
}
mMinuteSpinner.setDisplayedValues(displayedValues
.toArray(new String[0]));
} catch (Exception e) {
e.printStackTrace();
}
}
}