2012-02-08 74 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