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?
Why isn't it a default behavior?



On Dec 18, 11:20 am, Mark Murphy <mmur...@commonsware.com> wrote:
> loty wrote:
> > I can definitely do the same but it seems super strange to me that it
> > would return anything other than what I created in the initial call.
>
> getView() gets called more than once.
>
> > Is there any rhyme or reason for what this function gets in the
> > convertView parameter?
>
> Sure. It's a View that is being recycled. It is one of the ones you
> created earlier. Exactly *which* one of the ones you created earlier is
> unpredictable, since it is based upon user actions, mostly scrolling or
> otherwise traversing the list.
>
> > Very very mysterious explanation - we'll send you a view and it may or
> > may not be the right view.
>
> My guess is that you are thinking of lists containing only a single sort
> of entry.
>
> There's nothing in the AdapterView API that requires all Views returned
> by the adapter's getView() to all be the exact same type of View.
>
> There is nothing preventing you from creating an Adapter that returns
> multiple disparate types of views. For example, I have a ListView that
> returns Views for email addresses, phone numbers, mailing addresses, and
> what could best be described as "menu choices". Each of those views are
> a bit different in their layout.
>
> That's part of the reason they added in getViewTypeCount() and
> getItemViewType(int position), to help them be more efficient about the
> recycling process, to increase the odds that the convertView passed into
> getView() is one you *can* recycle.
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to