I am trying to change the background color of my recyclerview row when it is clicked. When one row is clicked, its background color is changed. If another row is clicked, then the previous row changes back to its old state and the newly clicked one changes color.
I've tried achieving this using selectors
, but when i release the touch, the color just goes back to normal and none of my rows are highlighted.
Would anyone have an idea how to approach this? Thanks in advance
Here is my selector code - Desired goal (Selected row STAYS charcoal until another row is selected)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_pressed="true" android:drawable="@color/charcoal_dark" />
<item android:state_enabled="true"
android:state_focused="false" android:drawable="@color/charcoal_dark" />
<item android:drawable="@color/black"/>
</selector>