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);
Erik
  • 5,039
  • 10
  • 63
  • 119

1 Answers1

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;

}
Erik
  • 5,039
  • 10
  • 63
  • 119
  • It´s the [custom object](https://stackoverflow.com/questions/27475434/how-to-use-an-arrayadapter-in-android-of-custom-objects) in the adapter – Erik Aug 11 '17 at 08:38
  • OK but add it in a note, so people will not get confused – Joy Hard Aug 11 '17 at 08:43