Android: Expand the inputType of EditText?

混江龙づ霸主 提交于 2019-12-10 20:47:52

问题


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

}


回答1:


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.



来源:https://stackoverflow.com/questions/3961960/android-expand-the-inputtype-of-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!