Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Error Android

Can anybody tell me how to use setError function appropirately for CheckBoxes and RadioButtons. I am able to raise the error icon symbol (!) after my textView but cannot see the error message . As per Android's documentation :
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.
Can you someone provide an example of the proper implementation of setError in case of checkbox aand radioButton?

Here is my code -

CheckBox box=(CheckBox)findViewById(R.id.propertyStatus1);
box.setError("Error");
like image 958
Code_Life Avatar asked Feb 08 '12 07:02

Code_Life


People also ask

How can I get error message in Android?

Solution: We can display error message in EditText by using setError() method.

How do I show error in TextInputLayout?

To display the error text, we'll have to call the method setError(String) on an instance of TextInputLayout in our MainActivity. java class as shown below. Note: The indicator of the text field uses the same color as the error label. It overrides the color set by counterOverflow hence has the highest priority.


1 Answers

To display the seterror for checkbox and radiobutton its working. Your code also right for displaying set error.

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

At first only the error icon will be displayed. When focus went the error message will be displayed.

To receive focus on these types of elements add android:focusableInTouchMode="true"

like image 141
user1213202 Avatar answered Nov 13 '22 18:11

user1213202