Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView reusing views when ... I don't want it to

Tags:

android

I've got a ListView, each of item of which contains a ToggleButton. After I toggle it and then scroll up or down, the ListView is recycling the Views and so some of the others are mirroring the checked state of the ToggleButton. I don't want this. How can I prevent it?

like image 762
LuxuryMode Avatar asked Aug 03 '11 03:08

LuxuryMode


People also ask

Does listview recycle views?

One of the features of ListView , if I understood it right, is that it recycle views and just replaces it with new data when an item is off the screen.

What is a custom list view?

What is custom listview? Custom listview works based on customAdapter. In this custom adapter we can pass custom object. We are passing subject data to listview as shown below − Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.


1 Answers

Add this two methods to your Adapter.

@Override  public int getViewTypeCount() {                       return getCount(); }  @Override public int getItemViewType(int position) {      return position; } 
like image 185
Lilo Avatar answered Oct 05 '22 23:10

Lilo