cody
cody

Reputation: 6941

Android: Expand the inputType of EditText?

I'd like to allow possible inputs of 0-9, "," or "-" for EditText and couldn't find an answer.

I know using the "|" as an separator is possible:

android:inputType="number|text"

But how can I archive something like this (too bad it doesn't work):

android:inputType="number|,|-"

Does anyone know?

Regards,

cody


Addition 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',',','-'};
    }

}

Upvotes: 3

Views: 1814

Answers (1)

Cheryl Simon
Cheryl Simon

Reputation: 46844

I don't think there is a way to provide an arbitrary filter like that. You have to use the provided filter types.

If you can't find a combination of those types that does what you want, you probably need to do the filtering yourself using a TextWatcher or InputFilter on the EditText.

Upvotes: 2

Related Questions