Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在具有指定数字的EditText上使用OnEditorActionListener_Java_Android - Fatal编程技术网

Java 在具有指定数字的EditText上使用OnEditorActionListener

Java 在具有指定数字的EditText上使用OnEditorActionListener,java,android,Java,Android,我有一个EditText,它只接受小写字母字符,这是我使用数字实现的 <EditText android:id="@+id/play_edit_enter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:maxLength="1" android:inputType="textNoSuggesti

我有一个EditText,它只接受小写字母字符,这是我使用
数字
实现的

<EditText
    android:id="@+id/play_edit_enter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:maxLength="1"
    android:inputType="textNoSuggestions"
    android:digits="qwertyuiopasdfghjklzxcvbnm"
    android:layout_marginTop="100dip"
    android:textSize="20sp"
    android:layout_centerHorizontal="true"
    android:imeOptions="actionDone"
    />
如果我去掉android:digits=“qwertyuiopasdfghjklzxcvnm”行,这就可以了。但我想用这句话。也许它不起作用的原因是因为这些数字中不包括回车键

Q:如果是这样,我需要补充什么?否则,我该怎么做

如果我去掉android:digits=“qwertyuiopasdfghjklzxcvbnm”行,这就可以了。但我想用这句话

您应该删除该行,因为它不会做您认为它会做的事情。它实际上指定EditText只接受数字,并且只接受您在值中指定的数字,在您的示例中,该值是
“qwertyuiopasdfgfghjklzxcvnm”
,它显然没有数字

也看到

android:digits

如果设置,则指定此TextView具有数字输入方法,并且这些特定字符是它将接受的字符。如果设置了该值,则表示numeric为true。默认值为false

我知道它说的是TextView,但EditText继承了TextView的属性

您可以做的是检查
@android:inputType
,看看它是否能为您做些什么

    progressEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                progressButton.performClick();
                return true;
            }
            return false;
        }
    });