谁能告诉我如何对CheckBoxes和RadioButtons正确使用setError函数。我可以在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");

最佳答案

显示复选框的seterror并单选按钮使其工作。您的代码也可以正确显示设置错误。

    CheckBox cb=(CheckBox)findViewById(R.id.checkBox1);
    cb.setError("error");

首先,将仅显示错误图标。聚焦后,将显示错误消息。

要关注这些类型的元素,请添加android:focusableInTouchMode="true"

10-07 19:25
查看更多