2012-02-08 48 views
7

任何人都可以告诉我如何适当地使用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和单选按钮的情况下,适当实施SETERROR的例子吗?

这里是我的代码 -设置错误Android

CheckBox box=(CheckBox)findViewById(R.id.propertyStatus1); 
box.setError("Error"); 
+0

你的问题不明确 – Snicolas 2012-02-08 07:47:13

+1

SETERROR邮件不在复选框,单选按钮的情况下可见。 – 2012-02-08 07:49:24

回答

17

要为复选框,单选按钮的工作显示SETERROR。您的代码也适用于显示设置错误。

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

起初只会显示错误图标。焦点转到时,将显示错误消息。

要接收专注于这些类型的元素添加android:focusableInTouchMode="true"

+0

这就是我想告诉...如何将你的设备上的radioButton和复选框集中。 U必须测试AVD上的代码,请在设备上尝试相同的代码。 – 2012-02-17 11:45:16

+0

好的。现在我明白你的问题。设置这个属性为你的复选框在XML文件。 android:focusableInTouchMode =“true”。通过设置这个,只要你碰到你可以得到我想的信息,只需尝试一下。 – user1213202 2012-02-17 11:55:26

+0

嗯,它不适合我,它是禁用我的editText框... – Lion789 2014-02-07 00:17:59