Search code examples
androidlistviewbaseadapter

Android list view adapter hiccup


So I have noticed something weird in Android List Adapters.

I have an adapter that is inflated with lets say template.xml, this template has a text view (TextView1 default: "hello"). In some cases TextView1 must have a value of "not now" and in other cases nothing (ie the default should be displayed). When the list contains all the default values everything is ok.

But as soon as in the GetView of a specific adapter I change it to "not now" it effects the others as well (not always if I close the activity and reopen it it may work).

What do you guys think?


Solution

  • That behavior happens as intended.

    The adapter recycles views through the use of convertView, which means that, for example, a view that you returned on position 10 can be reused on position 19.

    For example: If you set your position 10 to be "not now", and didn't change it back to the default value in your getView method in the position 19, it will keep the value you set for position 10.