tags:

views:

106

answers:

1

Hello -

I am trying to modify this example:

http://developer.android.com/resources/tutorials/views/hello-gridview.html

But instead of displaying images that are resources, I want to display Drawables that I currently am storing in a List.

Can anyone instruct me on how I would modify

 private Integer[] mThumbIds = {
         R.drawable.sample_2, R.drawable.sample_3,
         R.drawable.sample_4, R.drawable.sample_5,
         R.drawable.sample_6, R.drawable.sample_7,
         R.drawable.sample_0, 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,
         R.drawable.sample_0, 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
 };

To display my drawable items instead?

Thanks!

+1  A: 

You only have to change a few minor things. In 'imageView.setImageResource(mThumbIds[position]);' you have to replace the array accessor by mThumbIds.get(position) and 'mThumbIds.length' becomes 'mThumbIds.size()'.

This is untested, but I think that is all you need.

Maurits Rijk
Would I also change SetImageResource to SetImageDrawable?
Tyler
If you are holding the actual Drawables in your list (instead of resource id's), yes.
Maurits Rijk
Yes! Perfect, it worked, thank you... Now I just have one more quick question if you don't mind.. What is the best approach pragmatically speaking to pass mThumbIds to the class ImageAdapter? Essentially, I am filling the List mThumbIds with the drawables, so I decided to just get lazy with it and make mThumIds a global variable so that I could fill it in my main function and access it from ImageAdapter, but I am thinking that is probably frowned upon.. Thanks again!
Tyler