loty wrote: > Thanks a lot Mark - excellent explanation. > Still have a question: > > getView's first 2 parameters are > --position-- The position of the item within the adapter's data set > of the item whose view we want. > --convertView-- The old view to reuse, if possible. Note: You should > check that this view is non-null and of an appropriate type before > using. If it is not possible to convert this view to display the > correct data, this method can create a new view. > > So getView knows the position that I need to fill - why not return a > view that I created for that position in the previous call?
Possibly, you haven't created such a View yet. Possibly, the View you did create was recycled already. > Why isn't it a default behavior? I'm not sure what "it" is. Imagine a ListView on an adapter with 1,000,000,000 entries. It is impractical to maintain a roster of 1,000,000,000 Views. What AdapterView does is maintain a pool of Views. The minimum size of the pool is enough Views to fill the visible area of the selection widget (e.g., enough rows for a ListView). I suspect it holds onto a few more, particularly Views that recently scrolled off one end, in case the user backs up. However, I haven't poked around the source code to AdapterView and so have no proof for this guess. However, I feel quite confident it does not intend to hold onto 1,000,000,000 Views. When getView() is called, you are handed a candidate View out of that pool, to repopulate (if practical) or replace (if not). I have seven blog posts on this and related topics over on AndroidGuys: http://androidguys.com/?s=fancy+listviews&x=0&y=0 Note that most are for the M5 SDK, so the literal code may not work properly without adjustment in some cases. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Published! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---