Android: Expand inputType for EditText?

I would like to allow possible inputs 0-9, "," or "-" for EditText and could not find the answer.

I know using "|" as a separator is possible:

android:inputType="number|text"

But how can I archive something like this (this does not work too bad):

android:inputType="number|,|-"

Somebody knows?

Hi,

Cody


Adding to the comment below:

private class MyKeylistener extends NumberKeyListener {

    public int getInputType() {
      return InputType.TYPE_CLASS_NUMBER;
    }
    @Override
    protected char[] getAcceptedChars() {
      return new char[] {'0','1','2','3','4','5','6','7','8','9',',','-'};
    }

}

+3
source share
1 answer

I don’t think there is a way to provide such a filter. You must use the provided filter types .

, , , , , , TextWatcher InputFilter EditText.

+2

Source: https://habr.com/ru/post/1770164/


All Articles