I have a problem
How do I show prechecked checkboxes in my android application.
Suppose there are 4 check boxes and I want to show 2 of them checked from the beginni
You can either use xml property
<CheckBox
android:id="@+id/cb1"
....
android:checked="true"
/>
or set in your code like
boolean isChecked = ...;
CheckBox cb1 = (CheckBox)findViewById(R.id.cb1);
cb1.setChecked(isChecked);
Just set your value in
checkBox.setTag("zero")
or
checkBox.setTag("one")
and check like this ...
String str = (String) checkBox.getTag();
if(str.equals("zero") || str.equals("one") ){
checkBox.setChecked(true);
}
Vladimir's answer didn't work for me. Instead use this:
<CheckBox
...
android:state_checked="true" />