I'm having a weird behavior. I've created a custom TimePickerDialog
to handle custom minute intervals (5, 10, 15) to display on the minute spinner.
The problem is that now, on Note 4 with Lollipop 5.0.1 I'm facing a strange problem: If I try to set the time with the keyboard, the numbers on the minute spinner disappears and I cannot enter any value; on the hour spinner there is no problem instead.
On the logcat, when I click on the minute spinner, I'm having these two warnings (maybe related):
09-15 10:18:26.790: W/IInputConnectionWrapper(19382): getTextBeforeCursor on inactive InputConnection
09-15 10:18:26.790: W/IInputConnectionWrapper(19382): getCursorCapsMode on inactive InputConnection
This is my code for the custom TimePickerDialog.onAttachedToWindow()
method:
@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_interval) - 1);
// List<String> displayedValues = new ArrayList<String>();
for (int i = 0; i < 60; i += time_interval) {
displayedValues.add(String.format("%02d", i));
}
mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0]));
Field numberpickerField = classForid.getField("numberpicker_input");
EditText mInputText = (EditText) mMinuteSpinner.findViewById(numberpickerField.getInt(null));
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
} catch (Exception e) {
e.printStackTrace();
}
}
Solved.
On Android 5.0.1, on Samsung Note4 at least, in my case there is a problem with the values passed to the timePicker.
mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0]));
The values passed to setDisplayValues()
need to be normal numbers {"0","1","2","3"..}
and not 2digit numbers {"00", "01", "02"..}
to work properly.
Just for laughing a little bit more...
Lollipop 5.1.1, tested again on Note4, doesn't have this strange behaviour
Hope to have been useful for someone. Cheers