0

I have an application that has a listview and I would like to highlight a particular list item when the user is on that activity.

So far I have a general implementation where I am creating a listView and I have an OnListItemClick method. I would appreciate it if someone could provide a sample implementation of how to highlight a particular listitem in a listview.

RagHaven
  • 4,156
  • 21
  • 72
  • 113

1 Answers1

0

It should be done automatically, but otherwise you can do what I wrote here: How can I highlight the table row on click ?

Set the background of the view you are inflating in your Adapter.getView() method to android:background="@android:drawable/list_selector_background"...

Community
  • 1
  • 1
Salil Pandit
  • 1,498
  • 10
  • 13
  • I dont want to highlight it on clicking it. I would like to highlight the 2nd list item in my listview whenever I go to that screen. – RagHaven Jun 24 '12 at 22:43
  • ahh than in your adapter do the following: `if(position == 1 || item.equals(itemToHighlight)) //not sure if you want to do it by position or the item itself, its up to you, remove one or the other { convertView.setBackground(R.color.highlight_color); { else { convertView.setBackground(android.R.color.transparent); }` – Salil Pandit Jun 26 '12 at 20:41