任何人都可以告诉我如何使用setError函数适当地使用CheckBoxes和RadioButtons。我能够在textView之后引发错误图标符号(!)但看不到错误消息。根据Android的文档:
sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.
在复选框a和radioButton的情况下,你能否提供一个正确实现setError的例子?
这是我的代码 -
CheckBox box=(CheckBox)findViewById(R.id.propertyStatus1);
box.setError("Error");
答案 0 :(得分:18)
显示复选框和radiobutton的seterror工作。您的代码也适用于显示设置错误。
CheckBox cb=(CheckBox)findViewById(R.id.checkBox1);
cb.setError("error");
首先,只会显示错误图标。当焦点移动时,将显示错误消息。
要获得对这些类型元素的关注,请添加android:focusableInTouchMode="true"