简体   繁体   中英

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

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM