In my adapter code I only ever return a single type of view from getView(). This view always has a field with an id of R.id.name.
A non-zero percentage of the time I am given a convertView in the parameters passed to getView() and the code: convertView.findViewById(R.id.name) will return null. I have no idea what view the framework is passing to me, but it bears no resemblance to anything I returned from getView. On Dec 18, 10: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 -~----------~----~----~----~------~----~------~--~---