1

I'm having some difficult time figuring out when the ListView decides to recycle all it's views. I have 2 different ListViews where i change some layout stuff and play an animation after that. In my first ListView this works fine, only the row i'm trying to change is actually being affected, yet in my other ListView all rows are affected and the Views are being reused.

I can't really post any code, as there are quite a few classes involved in this. I tried to break it down and noticed it reuses the rows after calling requestLayout() at one of the descendant views of the row. But in my other ListView i do the same and it's not called at all.

Nowhere in my code notifiyDatasetChanged() is called either, nor am i changing any other views.

I just trying to find out when ListView actually needs to reuse the views.

ps. I'm using 2.3.3. And i'm aware of setHasTransientState() in 4.1. But i can't use that unfortunately

Nick
  • 1,733
  • 1
  • 14
  • 24
  • for understanding of `Listview` recycling mechanism you can refer to my post http://stackoverflow.com/a/14108676/1939564 – Muhammad Babar Jun 26 '13 at 04:55
  • Maybe i phrased my question wrong. I know how it works, what i want to know is when it starts using it. – Nick Jun 26 '13 at 06:09
  • as soon as it has some scrap views which `ListView` can recycle to create new upcoming views as you scroll up/down – Muhammad Babar Jun 26 '13 at 06:12
  • Yeah, but it was doing it already without scrolling, just after a change in the layout in one of the child views – Nick Jun 26 '13 at 07:09
  • its normall because there is no gurantee of how many times `getView()` will get called and in which sequence, just make sure you never set your `ListView's` width/ height to `wrap_content`!! – Muhammad Babar Jun 26 '13 at 07:17
  • when ever `notifyDatasetChanged()` get called `getView()` get refresh and tries to measure the child view's (row) so some time it might happen you see `convertView` not null even you the `ListView` didn't scroll – Muhammad Babar Jun 26 '13 at 07:20
  • Like i said, no scrolling and `notifiyDatasetChanged()` wasn't called either. I understand that when either of those happen and what the consequences were. What i didn't understand was that the rows were recycled when none of those events occurred. But i found out what the problem was, i put it as an answer below – Nick Jun 26 '13 at 11:31
  • Did your `ListView` width/height was `wrap_content`? – Muhammad Babar Jun 26 '13 at 13:17
  • No they both were `match_parent` – Nick Jun 27 '13 at 08:23

1 Answers1

1

I found my specific problem.

After long debugging through the source of the ListView I found the difference in behavior between my two ListView implementations. I found out that one of them was calling onSizeChanged(), first to a new height immediately followed by another onSizeChanged() with the old height. In this method it sets a flag mDataChanged which in turn will cause the views to be recycled.

In my other ListView i have fixed row heights so it never has this problem. I'm going to do the same for this situation as i don't really need different row heights.

Nick
  • 1,733
  • 1
  • 14
  • 24