Reputation: 3267
I looked at the documentation for CheckBox and I see these two methods:
setEnabled(boolean)
setSelected(boolean)
So, in my code, I put
CheckBox myCB = (CheckBox) findViewById(R.id.CheckBox);
myCB.setEnabled(true);
myCB.setSelected(true);
When I run the code, I want the above CheckBox to already be checked and turned 'on' in the GUI. But it isn't. It looks like it's unchecked. What am I doing wrong?
Upvotes: 1
Views: 54
Reputation: 19290
Use setChecked(boolean checked)
or toggle()
instead. Take a look at the javadoc for CheckBox here.
Notice that, for instance, setSelected(boolean selected)
is inherited from TextView, and is used to determine the presentation of the text, not to check or uncheck the CheckBox.
Upvotes: 1