Use*_*263 5 validation android android-edittext
我有一个包含a EditText和a 的XML布局文件Button.我想显示以下验证消息以向用户提供反馈:
您必须输入4个数字
完成此任务的最佳方法是什么?
Cri*_*ian 13
根据我的经验,这是最好的方法:
EditText yourEditText;
// when you detect an error:
yourEditText.setError("Input must be 4 digits and numeric");
Run Code Online (Sandbox Code Playgroud)
结果是:

此外,如果输入必须是数字,请android:inputType="numberSigned"在EditText定义中使用.这样设备将不允许用户输入非数字值; 更好的是,它会显示一个特殊的键盘:
