0

My app has a list view and 2 buttons, send and delete. I need to select one item of a list view and then, depends of the next button pressed, the item will change its background and text color.

I've done it using OnItemClickListener, changing the color of the item pressed and saving its view to change it later. But it doesnt work, because when I scroll the list view, there are more views with their color changed!

The question is: How can I save a view of a ListView to change it whenever I want?

Thanks, I've read Programmatically select item ListView in Android and other questions but they dont help me in a 100%

P.D: Sorry for my english

Community
  • 1
  • 1

1 Answers1

0

You have to save state of a row to implement this, you should take a list of boolean variables and at start set them false like the following (in you adapter's constructor)

private ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
for (int i = 0; i < this.getCount(); i++) {
    itemChecked.add(i, false); // initializes all items value with false
}

then when you are clicking the item set the corresponding item true. And now check this list for true and change the color of the row where it found true.In this way it will not change color of other items in the list.

HpTerm
  • 8,151
  • 12
  • 51
  • 67
keshav
  • 3,235
  • 1
  • 16
  • 22
  • Is the same idea that http://www.lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html. Thanks anyway! – user2747294 Dec 17 '13 at 17:05