0

I want the image path from the drawable under resources as a string but it shows error . But I can't identify what the error is. I provide some code snippet.

listView = view.findViewById(R.id.listView);

ArrayList<Card> list = new ArrayList<>();

//here the error
String img = "drawable://" + R.drawable.tiger;

Note: when I placed image name (tiger) it gives me error

list.add(new Card("drawable://" + R.drawable.tiger, "Royal Bengal Tiger"));
aminography
  • 21,986
  • 13
  • 70
  • 74

2 Answers2

1

i want the image path from the drawable under resources

A drawable resource is a file on your development machine. It is not a file on the device. There is no path to it on the device.

i provide some code snippet

There is no drawable scheme in Android. This also is not an image path.

If your Card requires a Uri, you can try android.resource as a scheme.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Check this: https://github.com/mitchtabian/AppBarLayouts/blob/master/ActionBar%20CardView%20Tutorial/ActionBar/app/src/main/java/tabian/com/actionbar/Tab2Fragment.java – Sagar Chandra Chanda Jan 16 '19 at 19:32
  • You would need to talk to the developer of that tutorial. We cannot help you with that tutorial, as we did not write it. – CommonsWare Jan 16 '19 at 19:34
1

That's not how you get resources

what you want is ContextCompat.getDrawable(context, R.drawable.name);

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • Check this: https://github.com/mitchtabian/AppBarLayouts/blob/master/ActionBar%20CardView%20Tutorial/ActionBar/app/src/main/java/tabian/com/actionbar/Tab2Fragment.java – Sagar Chandra Chanda Jan 16 '19 at 19:31
  • That example uses a library called `Universal Image Loader` without going through that library and seeing what is does with that string I cant tell you but its not behavior that you can get without it – tyczj Jan 16 '19 at 20:01