使用EditText的android:digits 属性 或者 android:inputType 属性来指定该文本框输入指定的数据。
使用EditText提供的setError的方法 提示用户 输入的数据是否合法。
[img]http://dl2.iteye.com/upload/attachment/0086/7364/9867afed-e55d-3add-abb4-b750cde6d237.jpg[/img]
<EditText
android:id="@+id/num"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:digits="1234567890"
/>
使用EditText提供的setError的方法 提示用户 输入的数据是否合法。
String value = editText.getText().toString();
if (value == null || value.trim().equals("")) {
editText.setError("请输入数字!");
}
[img]http://dl2.iteye.com/upload/attachment/0086/7364/9867afed-e55d-3add-abb4-b750cde6d237.jpg[/img]