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"));
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 .
That's not how you get resources
what you want is ContextCompat.getDrawable(context, R.drawable.name);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.