Gallery not Recycling Views

641 views
Skip to first unread message

Aamir Shah

unread,
May 26, 2010, 11:31:02 PM5/26/10
to Android Developers
I am using the Hello Gallery code as an example. Views are not being
recycled as I scroll left and right.

I added log output at the getView method, and I get a constant output
of null. Anyone know the reason why?

Here is the code:

public class HelloGallery extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Gallery g = new Gallery(this);
g.setAdapter(new ImageAdapter(this));

setContentView(g);
}

public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;

private Integer[] mImageIds = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};

public ImageAdapter(Context c) {
mContext = c;

}

public int getCount() {
return mImageIds.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup
parent) {
System.out.println(convertView); //should occasionally not be
null
ImageView i = new ImageView(mContext);

i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);

return i;


}
}

Thanks,
Aamir

Romain Guy

unread,
May 27, 2010, 4:45:51 PM5/27/10
to android-d...@googlegroups.com
This is a known "bug" (it's not a bug really, we just never had the
time to implement recycling in Gallery) but we have no ETA for a fix.

> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-d...@googlegroups.com
> To unsubscribe from this group, send email to
> android-develop...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

--
Romain Guy
Android framework engineer
roma...@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

Reply all
Reply to author
Forward
0 new messages