Question

In my application i created a button when the button is clicked it will load all images from the sdcard.

Was it helpful?

Solution

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();   
    }
});

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top