tags:

views:

655

answers:

2

I am using a GridView. It contains images. When I click on any item of this grid view I want this image Resource ID to be sent to another activity. Where can I display this image in larger size? How can I get Image Resource ID and send it to other activity?

+2  A: 

One way to do it is by modifying your getView() method of your adapter, so that it uses the ViewHolder pattern (Romain Guy's Google I/O 2009 presentation, look at 0:09:05).

In your view holder that you tag to the view, you can add field for the resource ID. When you get your selected view, find the view holder (view.getTag()) and get its ID field.

You can pass it to another Activity by using Intents.

You may have to use ContentProvider so that the second Activity has access to your chosen image. Keep in mind that, more often than not, the resources that are compiled in your .apk and have an ID are small, utility ones, because otherwise they bulk up your application, and most of the time, you can count on using the Internet to download images.

Of course, that's not always the case, but if you are simulating Internet resources with res/drawable resources, chances are, you'll face different problems.

Good luck.

Dimitar Dimitrov
+1  A: 

You can put this information in intent used for starting other activity:

final Intent showImage = new Intent(this, ImageDisplayActivity.class);
showImage.putExtra("RESOURCE_ID", resourceId);
startActivity(showImage);

And in the ImageDisplayActivity You will use

Bundle extras = getIntent().getExtras();
int entryId = extras.getInt("RESOURCE_ID");
JaanusSiim
in grid view onItemClick i get the item id by Gridviewobj.getItemIdByPosition(pos);but it return id in double not in int..... i m sad how to use double id in other activity for displayimg large images....
You also probably want to store that "RESOURCE_ID" as a constant in a static class. For example: ImageDisplayActivity.RESOURCE_ID
gregm