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");
Solution: We can display error message in EditText by using setError() method.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With