Reputation: 52
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"));
Upvotes: 0
Views: 369
Reputation: 73721
That's not how you get resources
what you want is ContextCompat.getDrawable(context, R.drawable.name);
Upvotes: 1
Reputation: 1006564
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.
Upvotes: 1