OpenSrcFTW
OpenSrcFTW

Reputation: 211

ArrayAdapter<Bitmap> help populating a GridView

So I have a layout which has a GridView. I'm trying to populate it with images. So, I fill an array with Bitmap objects and performed the following:

setContentView(R.layout.view_photos);
gridView = (GridView) findViewById(R.id.gridView1);
ArrayAdapter<Bitmap> adapter = new ArrayAdapter<Bitmap>(this,android.R.layout.simple_list_item_1, pix);
gridView.setAdapter(adapter);

To my dismay, the app simply crashes when I launch it.

I'm still a noob at android, but thanks for the help!

Upvotes: 0

Views: 1161

Answers (1)

dandc87
dandc87

Reputation: 1106

android.R.layout.simple_list_item_1 is a TextView. You are going to have to define a custom view with an ImageView in it. You will then have to override the getView method of the ArrayAdapter to populate the ImageView with the Bitmap. Do a quick google for something like "android arrayadapter custom view" for tutorial or example.

Upvotes: 1

Related Questions