How to pass a click on an image from one activity to another?
In my application i created a button when the button is clicked it wi开发者_开发问答ll load all images from the sdcard.
You just pass the path of image to another activity and then get image from that particular path in another activty. You can start activity inside of onItemClickListener. Just try this code.
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// Get the data location of the image
String[] projection = {MediaStore.Images.Media.DATA};
cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
// Get image filename
String imagePath = cursor.getString(columnIndex);
Intent i = new Intent(Images.this, GreetingCard.class);
i.putExtras("path",imagePath);
startActivity(i);
finish();
}
});
in button click event u write
startActivityForResult(new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
it show the all images in ur sdcard
if you can tell me by which method you are loading images from sdcard than ican help you more .you can send an id or name of image to other intent than in that activity you have to load that image again from its name or id.
精彩评论