Looking to disable the .
,?
, 1
,2
etc on the android keyboard.
I was thinking if
the key is entered, run a method that converts it from "."
to ""
for example.
Or just straight up disable them from being entered.
How do I go about this?
Looking to disable the .
,?
, 1
,2
etc on the android keyboard.
I was thinking if
the key is entered, run a method that converts it from "."
to ""
for example.
Or just straight up disable them from being entered.
How do I go about this?
You can't disable the keys on the soft keyboard like that... the closest to that functionality would be specifying inputType
for the EditText
but obviously that only works with things like number
, and you can't do that for a specific custom set of keys like the set you mentioned.
Instead look into InputFilter
, as explained here:
How do I use InputFilter to limit characters in an EditText in Android?
Specifically the second answer (with modified if statements to fit your requirements):
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
if (source instanceof SpannableStringBuilder) {
SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder)source;
for (int i = end - 1; i >= start; i--) {
char currentChar = source.charAt(i);
if (currChar=='.' || currChar=='?' || Character.isDigit(currChar) && !Character.isSpaceChar(currentChar)) {
sourceAsSpannableBuilder.delete(i, i+1);
}
}
return source;
} else {
StringBuilder filteredStringBuilder = new StringBuilder();
for (int i = start; i < end; i++) {
char currentChar = source.charAt(i);
if (currChar=='.' || currChar=='?' || Character.isDigit(currChar) && !Character.isSpaceChar(currentChar)) {
filteredStringBuilder.append(currentChar);
}
}
return filteredStringBuilder.toString();
}
}
}