Reputation: 1065
I've got a (hopefully) simple question. My program has a ListView
to display some data. When an item is pressed, I call the setChecked
method on it to mark it as checked. How do I have this "checked" item appear highlighted or in a different style? I was doing some reading on this and found a lot of things that had to do with check-boxes, but I just want to highlight an item that is "selected" by tapping it.
EDIT: I do have a selector setup as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/category_tab_s" android:state_checked="true"/>
<item android:drawable="@drawable/category_tab"/>
</selector>
However, it never applies the checked state. When I press items the category_tab
state is activated.
Upvotes: 0
Views: 208
Reputation: 4460
Please check below link :
http://android-codes-examples.blogspot.in/2011/03/customized-listview-items-selection.html
Or on the onclick event you just set
view.setBackground("Any Color");
If your going t some other activity after clicking on any of the row and coming back again to the listview activity again refresh listview so that color get removed and you will get fresh listview.
Upvotes: 1