pankajagarwal
pankajagarwal

Reputation: 13582

android change view of selected item in adapterview

I have a listview with a textview as each item. I want to change the textcolor of the selected item. For this use the onItemSelected method to make the changes. Say first I select the 1st row, the first row's textcolor changes. Now when I select the 2nd row, its text color also changes, but I want the 1st row's color to change back to its default color. How do I do that, since in the onItemSelected I only get the refernce of the currently selected item and not the last selected. Is there any way other than holding a reference to the last selected view.

Upvotes: 1

Views: 3615

Answers (2)

xevincent
xevincent

Reputation: 3734

Instead of doing it in Java, you can let android handles it in the xml file. See Color State List Resource.

Upvotes: 0

Ognyan
Ognyan

Reputation: 13600

When first item is selected store its position in instance variable of your activity, lets name it currentlySelected. Then combine with this Android: Access child views from a ListView in order to get the view at position currentlySelected and change it's textcolor.

Upvotes: 2

Related Questions