Need to access image for selected item in android gridview
I want to access the properties of an image when it is selected from a gridview. For example if I am using.
GridView gridview = (GridView) findViewById(R.id.imageGallery);
gridvie开发者_Go百科w.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position,long id)
{
//need code in here that I can do something like this.
//Get access to the integer value of the R.drawable.myimage
//use that int too do a lookup in a dictionary to check for existance
//can't see to find any code to get at the drawable associated with the image clicked in the grid, did intense debug
And data not easily visible at runtime
}
);
@Reid I think you will want to create a custom adapter (extend BaseAdapter or other) that holds a view class containing the metadata you need to get at, based on the position in the list. Possibly an easier way, but that is what I did in a ListView.. A couple of links:
http://developer.android.com/resources/tutorials/views/hello-gridview.html http://www.anddev.org/gridview-t5585.html
精彩评论