0

I have GridView populated with images of 6 fruits (from drawable-hdpi). like this: this is how my gridview is populated with 6 types of fruits

Now on selection, how can I come to know, what fruit the user has selected? Since I'm populating my images from drawables-hdpi, what would be the identifier and how to identify selection through it?

Thanks :)

mmBs
  • 8,421
  • 6
  • 38
  • 46
Zeeshan
  • 2,884
  • 3
  • 28
  • 47
  • You can create static array of your image ids and then it would be easier to identify the selection – moDev Apr 24 '13 at 10:17
  • @Mitesh i'm sorry, this is first time i'm playing with images. can you tell me, how does the id of my drawables-hdpi images look like? and where can i get it? – Zeeshan Apr 24 '13 at 13:33

2 Answers2

1

Try this way

private int imageList[] = { R.drawable.image_01, R.drawable.image_02,
    R.drawable.image_03, R.drawable.image_04, R.drawable.image_05
 };

OnClick, you can get the image id and display the image if needed

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
        // TODO Auto-generated method stub

         // Here you can do the necessary operation

}
moDev
  • 5,248
  • 4
  • 33
  • 63
1

If it's your first time with GridView and images, so why haven't you started from developer.android.com? Here you have an answer to your question.

mmBs
  • 8,421
  • 6
  • 38
  • 46