Reputation: 1171
I want to custom the check mark in my several checkedtextview. I wanted to use a "simple" solution, so i did that :
if(serviceChecked.isChecked()){
serviceChecked.setChecked(false);
serviceChecked.setCheckMarkDrawable(null);
} else {
serviceChecked.setChecked(true);
serviceChecked.setCheckMarkDrawable(R.drawable.ic_action_done);
}
I've two problems with this solution :
The first is, it's running only the first time, when I check one of my checktextview, uncheck, and check again, my drawable is not visible.
The second problem is, we can see again the "default" checkmarck (the blue)....
How can I resolve it ?
Thx,
Upvotes: 1
Views: 2081
Reputation: 39718
Extending the CheckTextBox, you shouldn't need to change the setCheckMarkDrawable
. Just set it once, and the setChecked
should appropriately set the checked/non-checked state. Your drawable should be defined in XML, something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/checkbox_checked" /> <!-- checked -->
<item android:state_pressed="true"
android:drawable="@drawable/checkbox_checked" /> <!-- pressed -->
<item android:drawable="@drawable/checkbox_default" /> <!-- default -->
</selector>
Upvotes: 4