i have used imageview , checkbox on imageview single row in recyclerview. have put background of checkbox below codes. after displaying rows, when m checking checkbox particular position image changing in position simultaneously same effect occurring in other position have not checked.
help figure out error, m not getting whats wrong.
<?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/ic_love_dark_red" /> <!-- pressed --> <item android:state_checked="false" android:drawable="@drawable/ic_love_holo_blank" /> <!-- focused --> <item android:drawable="@drawable/ic_love_holo_blank" /> </selector>
you cannot have functionality (change picture on state changed) made in xml file because single instance of checkbox widget used multiple times in recyclerview, depending on size of data displaying. basically, recyclerview uses view holder pattern (of invite read if you're not familiar it), making image change on multiple rows. what need do:
- have "ischecked" attribute in object of data list made
- implement on state changed check box , synchronize newly updated state ischecked flag of current object
- when bind view holder, check whether flag true or false , update layout according flag.
hope work, cheers!
Comments
Post a Comment