1

我只需要输入以下字符0-9_

EditText 中选择什么“android: inputType”?

4

4 回答 4

1

就这样做XML

android:digits="0123456789_"
于 2013-03-07T14:14:50.023 回答
0

尝试将此添加到您的EditText

EditText text = findViewById(R.id.your_edit_text); /* Find your EditText here. */
text.setKeyListener(DigitsKeyListener.getInstance("0123456789_"));
于 2013-03-07T13:31:58.317 回答
0

如果您只想输入数字,请选择此项android:digits="0123456789_"

于 2013-03-07T14:10:06.230 回答
0

好的。试试下面的代码

   InputFilter[] Textfilters = new InputFilter[1];
    Textfilters[0] = new InputFilter(){
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        // TODO Auto-generated method stub
        if (end > start) {

            char[] acceptedChars = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_'};

            for (int index = start; index < end; index++) {
                if (!new String(acceptedChars).contains(String.valueOf(source.charAt(index)))) {
                return "";
                  }
                }
             }
                return null;
        }

    };
 editxt.setFilters(Textfilters);
于 2013-03-07T14:27:09.223 回答