Thanks Romain, getView is now called for each row only once. Just one follow up question:
it seems that I am having a problem with the listviewadapter. resultsList = (ListView) this.findViewById(R.id.list); resultsList.setAdapter(new ResultsListAdapter(this,R.layout.row, currentSearch)); In my getView I am doing a request for each row to get the thumbnail image in a different thread: if (record.getImgURL().equals("none")) holder.thumbView.setImageResource(R.drawable.nothumb); else { String url = item.getImgURL(); makeRequest(position,url,null,false); } and handling the response from makeRequest() @Override public void onResponseCompleted(boolean success, int userId, int ticket, Request request) { if (success) { ... ViewHolder holder = (ViewHolder)resultsList.getChildAt(userId).getTag(); This works fine for the first 5 records, then this last line throws a null pointer exception because for some reason, even though the getview is called on the row represented by resultsList.getChildAt(userId) - which it must to call makeRequest anyway - the view hasn't been added to resultsList. Why is this happening? There are no convertViews yet / The screen fits 4 rows and I can scroll down to the fifth and it works fine, just the sixth row that isn't added to the resultsList. On Apr 14, 5:26 pm, Romain Guy <romain...@android.com> wrote: > This is not an issue, there is absolutely no guarantee on the order in > which getView() will be called nor how many times. In your particular > case you are doing the worst thing possible with a ListView by giving > it a height=wrap_content. This forces ListView to measure a few > children out of the adapter at layout time, to know how big it should > be. This is what provides ListView with the convertViews you see > passed to getView() even before you scroll. > > > > On Tue, Apr 13, 2010 at 1:32 PM, edzah <edzill...@gmail.com> wrote: > > this is a cross-post from SO . haven't got much attention over there > > so I am posting it here. orig here: > > >http://stackoverflow.com/questions/2618272/custom-listview-adapter-ge... > > > ---------------------------------------------------------------------------------- > > > I have a custom list adapter: > > > class ResultsListAdapter extends ArrayAdapter<RecordItem> { > > > in the overridden 'getView' method I do a print to check what position > > is and whether it is a convertView or not: > > > �...@override > > public View getView(int position, View convertView, ViewGroup > > parent) { > > System.out.println("getView " + position + " " + convertView); > > > The output of this (when the list is first displayed, no user input as > > yet) > > > 04-11 16:24:05.860: INFO/System.out(681): getView 0 null > > 04-11 16:24:29.020: INFO/System.out(681): getView 1 > > android.widget.relativelay...@43d415d8 > > 04-11 16:25:48.070: INFO/System.out(681): getView 2 > > android.widget.relativelay...@43d415d8 > > 04-11 16:25:49.110: INFO/System.out(681): getView 3 > > android.widget.relativelay...@43d415d8 > > 04-11 16:25:49.710: INFO/System.out(681): getView 0 > > android.widget.relativelay...@43d415d8 > > 04-11 16:25:50.251: INFO/System.out(681): getView 1 null > > 04-11 16:26:01.300: INFO/System.out(681): getView 2 null > > 04-11 16:26:02.020: INFO/System.out(681): getView 3 null > > 04-11 16:28:28.091: INFO/System.out(681): getView 0 null > > 04-11 16:37:46.180: INFO/System.out(681): getView 1 > > android.widget.relativelay...@43cff8f0 > > 04-11 16:37:47.091: INFO/System.out(681): getView 2 > > android.widget.relativelay...@43cff8f0 > > 04-11 16:37:47.730: INFO/System.out(681): getView 3 > > android.widget.relativelay...@43cff8f0 > > > AFAIK, though I couldn't find it stated explicitly, getView() is only > > called for visible rows. Since my app starts with four visible rows at > > least the position numbers cycling from 0-3 makes sense. But the rest > > is a mess: > > > * Why is getview called for each row three times? > > * Where are these convertViews coming from when I haven't scrolled > > yet? > > > I did a bit of reseach, and without getting a good answer, I did > > notice that people were associating this issue with layout issues. So > > in case, here's the layout that contains the list: > > > <?xml version="1.0" encoding="utf-8"?> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > > android" > > android:layout_height="fill_parent" > > android:layout_width="fill_parent" > > android:orientation="vertical" > > > > <TextView android:id="@+id/pageDetails" > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" /> > > > <ListView android:id="@+id/list" > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" > > android:drawSelectorOnTop="false" /> > > > </LinearLayout> > > > and the layout of each individual row: > > > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ > > android" > > android:layout_width="fill_parent" > > android:layout_height="108dp" > > android:padding="4dp"> > > > <ImageView > > android:id="@+id/thumb" > > android:layout_width="120dp" > > android:layout_height="fill_parent" > > android:layout_alignParentTop="true" > > android:layout_alignParentBottom="true" > > android:layout_alignParentLeft="true" > > android:layout_marginRight="8dp" > > android:src="@drawable/loading" /> > > > <TextView > > android:id="@+id/price" > > android:layout_width="wrap_content" > > android:layout_height="18dp" > > android:layout_toRightOf="@id/thumb" > > android:layout_alignParentBottom="true" > > android:singleLine="true" /> > > > <TextView > > android:id="@+id/date" > > android:layout_width="wrap_content" > > android:layout_height="18dp" > > android:layout_alignParentBottom="true" > > android:layout_alignParentRight="true" > > android:paddingRight="4dp" > > android:singleLine="true" /> > > > <TextView > > android:id="@+id/title" > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" > > android:textSize="17dp" > > android:layout_toRightOf="@id/thumb" > > android:layout_alignParentRight="true" > > android:layout_alignParentTop="true" > > android:paddingRight="4dp" > > android:layout_alignWithParentIfMissing="true" > > android:gravity="center" /> > > > </RelativeLayout> > > > Thank you for your time > > > -- > > 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 > > > To unsubscribe, reply using "remove me" as the subject. > > -- > Romain Guy > Android framework engineer > romain...@android.com > > Note: please don't send private questions to me, as I don't have time > to provide private support. All such questions should be posted on > public forums, where I and others can see and answer them -- 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