问题
Background
Note: I've been using listViews for ages, so I'm very familiar with how to work with adapters, ViewHolders, etc... so this issue doesn't make sense for me.
This time I got into a very weird behavior that for some reason occur only on 2 devices:
LG G2, with Android 4.2.2
Xperia J, with Android 4.1.2
The problem
The listView has its own BaseAdapter, which on some events I update its items collection within it (on the UI thread) , and call notifyDatasetChanged().
The problem is that on the problematic devices, calling this function calls getView only on some of the visible rows of the listView. For example, if rows 1,2,3,4,5 are visible, and I call notifyDatasetChanged , and I put log on getView, I can see it goes over 1,2,4,5 (skipped row 3).
Some clues
it always skips the row that the user clicks inside of it (each row has clickable views ) that triggers the notifyDatasetChanged calls .
Other devices handle the listview just fine : 2 Nexus 4 devices (each with a different version), Galaxy S2, and Galaxy S4 .
It doesn't matter if I call notifyDataSetChanged once or twice .
Even though I use my own BaseAdapter , I didn't change the way the ListView work. I didn't extend ListView.
For the BaseAdapter class, I've overriden the next functions:
- getViewTypeCount -returns 2
- getItemViewType - returns 0 or 1, depending on the type of the row
- getCount
- getItem
- getItemId - I don't need it, so I made it always return 0 (it won't help making it return the position instead).
- getView
- areAllItemsEnabled and isEnabled - always returns false , as all rows have inned views that only they need to handle clicking .
I didn't override any other method. Of course I created helper functions, but that's it.
The question
Why does it occur?
How come it occur only to some devices?
How can I solve this?
Is it possible it's a bug on some roms ?
If so, is there a good workaround for this, or should I really call getView on the problematic row (which works fine BTW, but it's just weird that I do this) ?
来源:https://stackoverflow.com/questions/25243341/why-doesnt-notifydatasetchanged-notify-all-visible-items