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?
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.
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");