Reputation: 1873
In my form, I hava a CeckBox and its required to be checked to submit. If it's unchecked, I call setError() to warn the user. But, once the error is displayed, it don't disappears, no matter the checkbox is checked or not. Other bug is that if the error text is much long, it appears incomplete. In landscape mode, it appears complete.
checkbox xml:
<CheckBox
android:id="@+id/reg_terms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Li e concordo com os Termos de Uso."
android:focusableInTouchMode="true"
android:focusable="true"
android:textColor="#000000"
android:checked="false"
/>
Validation (inside submitButtons's onClick):
if(!reg_terms.isChecked()){
reg_terms.setError("É preciso aceitar os Termos de Uso");
validation = false;
}
There isn't any "addOnFocusChangedListener" methot I could use to "dismiss" the error if user checks the box? And how could I avoid the error text to appears incomplete?
Viele danke für alle Hilfe. :D
Upvotes: 4
Views: 6890
Reputation: 2265
As far as clearing the error, you can add an OnCheckedChangeListener like this:
reg_terms.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if ( isChecked ) {
reg_terms.setError(null);
} else {
reg_terms.setError("É preciso aceitar os Termos de Uso");
}
}
});
Personally, I would extract the string into your R.strings as well and reference it in the XML and the code.
For the text wrapping, try adding reg_terms.setMaxLines(2)
to your code to allow text to fill up to 2 lines. I'm not sure if this will work, but it's worth a try.
Upvotes: 8