我有一个 XML 布局文件,其中包含一个 EditText
和一个 Button
。我想显示以下验证消息以向用户提供反馈:
You must enter 4 numbers
完成此任务的最佳方法是什么?
最佳答案
根据我的经验,这是最好的方法:
EditText yourEditText;
// when you detect an error:
yourEditText.setError("Input must be 4 digits and numeric");
结果是:
此外,如果输入必须是数字,请在 EditText
定义中使用 android:inputType="numberSigned"
。这样设备将不允许用户输入非数字值;更好的是,它会显示一个特殊的键盘来执行此操作:
关于android - 显示验证消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5082918/