I'm using a code that is not mine in my work. This code uses CheckedTextView, do this:
...
AlertDialog.Builder alert;
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
switch (soundPreference.getType()) {
case BOOLEAN:
CheckedTextView checkedTextView = (CheckedTextView) v;
boolean checked = !checkedTextView.isChecked();
((CheckedTextView) v).setChecked(checked);
switch (soundPreference.getKey()) {
case SOUND_ACTIVE:
sound.setAlarmActive(checked);
break;
...
works perfectly, the problem is that I want I want to change the checkbox graphic. Right now it looks like (defualt, I think):
and I want to get something like this:
if the CheckedTextView were defined in xml, know how to do it. My problem is not being defined in xml, do not know how to do it.
I found this: Customize the CheckedTextView for ListView but I do not know how to implement it
appreciate any help.
Thank you very much in advance
Example:
myCheckedTextView.setCheckMarkDrawable(R.drawable.icon);
This method allows you to set the check mark image dynamically. You should call it when setting up the CheckedTextView
.
The method in the developer reference just needs the id of the image resource you want to use.
There is also a version that takes a Drawable
as a parameter instead of an id.
You need to create a custom list_item layout.
For full explanation go through the below link...
http://amitandroid.blogspot.in/2013/09/android-custom-multiple-choice.html
Hope this will help you.
来源:https://stackoverflow.com/questions/18878928/custom-a-checkedtextview-in-android