1

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.

Akram
  • 7,548
  • 8
  • 45
  • 72
pankajagarwal
  • 13,462
  • 14
  • 54
  • 65

2 Answers2

2

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.

Community
  • 1
  • 1
Ognyan
  • 13,452
  • 5
  • 64
  • 82
0

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

xevincent
  • 3,674
  • 18
  • 20