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;

}
Sign up to request clarification or add additional context in comments.

2 Comments

It´s the custom object in the adapter
OK but add it in a note, so people will not get confused

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.