1
ImageView image = ((ImageView) arg1.findViewById(R.id.imageView1));

How can I programmatically get the path/resource of that image? Thanks.

PS : I know I can set it this way :

image.setImageResource(resource)
5
  • the source you mean the content of the imageiew? Commented Jul 10, 2013 at 10:36
  • @blackbelt Sorry, I've corrected the question. Commented Jul 10, 2013 at 10:37
  • I don't think that's possible as an ImageView uses a Bitmap or a Drawable, not a File. Commented Jul 10, 2013 at 10:38
  • It's imposible. You could subclass ImageView a keep a String reference to the path Commented Jul 10, 2013 at 10:39
  • you want get image path from sdcard in mobile ? Commented Jul 10, 2013 at 11:14

3 Answers 3

2

It is hard to say you can get its path, but you can get its URI by this way:

Uri fileUri = Uri.parse("android.resource://your_packagename/" + R.drawable.your_image_id);
Sign up to request clarification or add additional context in comments.

Comments

1

You can do that in this way :

//Add image path/resource to the tag
ImageView image = ((ImageView) arg1.findViewById(R.id.imageView1));
image.setImageResource(R.id.yourImage);
image.setTag(R.id.yourImage); //also can be done via xml.

//Get image path/resource from the tag
ImageView image = ((ImageView) arg1.findViewById(R.id.imageView1));
Integer imageId = (Integer)image.getTag();

Comments

0

It is not possible to get the exact path for an image , that is stored in drawable.

you can use this to get drawable

 getResources().getDrawable(R.drawable.imageView1);

Comments

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.