How to change the picture in checkBox? I have a list of directories. It is possible to select these directories, if the directory is selected then a check mark is placed in the checkbox in front of it. If the directory is not selected, the checkbox in front of it is empty. I need to somehow mark the third state when there are selected subdirectories inside the directory, but this directory itself is not selected.
- it's very simple - wait for the regiment to get telepaths out of the holidays and decipher the question, there is a more complicated and long way to try to write in more detail what you need)) - gadfil
- Did I understand correctly that you want to get something like this? ! [alt text] [1] [1]: i.imgur.com/5niAmBy.png - falstaf
- Yes! exactly this - GLOCTARR
3 answers
We'll have to do instead of Checkbox usual ImageView. Then change the picture, depending on the 3 options: yes, no, partially. change method:
imageView.setBackgroundResource(R.drawable.checked); imageView.setBackgroundResource(R.drawable.unchecked); imageView.setBackgroundResource(R.drawable.both); Then make a custom checkbox and determine which one is needed, depending on this, set the background - if the directory is selected, or there are no selected subdirectories in it - normal, there are selected custom subdirectories.
Yes, the custom only for the third state, when there are subdirectories, in other cases, the usual checkbox is enough.
The screen is inserted using the button
- "there are selected custom subdirectories" you mean, use the custom checkbox for the third state, and use the usual checkbox for the other two. Or just change the background for the third state, and for the other two not to change the background? And also, how can I throw my screen here? - GLOCTARR
<CheckBox android:id="@+id/cbHelper" android:layout_width="match_parent" android:layout_height="match_parent" android:button="@drawable/check_box" android:checked="true"/> In the dravable folder, make the file check_box.xml:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/check_box1" /> // ΠΊΠ°ΡΡΠΈΠ½ΠΊΠ° Ρ Π³Π°Π»ΠΎΡΠΊΠΎΠΉ <item android:state_checked="false" android:drawable="@drawable/check_box2" /> // ΠΊΠ°ΡΡΠΈΠ½ΠΊΠ° Ρ ΠΊΡΠ΅ΡΡΠΈΠΊΠΎΠΌ </selector> Pictures of check_box1 and check_box2 in png format should be put right there in the dravable folder.
- need for three states checkbox - pavlofff