GOAL: Use EditTextPreference
to take a number input from an user.
PROBLEM: I'm using support.v7.preference
and, from what I've understood, this library bring problems to creates a custom DialogPreference
(HowTo use support.v7.preference with AppCompat and potential drawbacks). Anyway I tried to create a NumberPickerPreference
extending DialogPreference
but I got ClassCastException
.
Also I found another approach: programmatically set the input type of an EditTextPreference
object like below:
EditTextPreference pref = (EditTextPreference) findPreference("pref_edit_text");
if (pref != null) {
pref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
}
No way, I always get a ClassCastException
.
Last approach I tried : modify the xml
android:inputType="numberDecimal"
android:digits="0123456789"
or android:numeric="integer"
No way again, on the Dialog
I get the full keyboard, so the user can write everything.
Is there a way to properly enforce EditTextReference
to take just number input?