1

Got stuck a bit since i cannot understand how to get the path from a picture i click in the GridView.

This listener is the problem since i load the GridView with images from a folder on the sdcard.

public void onItemClick(AdapterView parent, View v, int position, long id)

I can only see example on how to use the "position" when the GridView is loaded from resources.

Can anyone give me a hint how to do this. Im reading and trying this

String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection,
null, 
null, 
null)

But that will give me all images from sdcard root. My folder is "sdcard/PTPPservice"

I will from here send an intent to show the image like:

      Intent intent = new Intent(getApplicationContext(), ViewImage.class);
      intent.putExtra("filename", imagePath);
      startActivity(intent);

1 Answer 1

4

Found the solution, so i answer my own quesion. The orgPath is a string i added and saves the path during loadind of images

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {    

    ImageAdapter i = (ImageAdapter)parent.getAdapter();
    LoadedImage l = (LoadedImage)i.getItem(position);

    Intent intent = new Intent(getApplicationContext(), ViewImage.class);
    intent.putExtra("filename", l.orgPath);
    startActivity(intent);
    return;

}
2
  • It´s the custom object in the adapter
    – Erik
    Aug 11, 2017 at 8:38
  • OK but add it in a note, so people will not get confused
    – Joy Hard
    Aug 11, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.