I have to show a drawable
from res
into an ImageView
. In this app, I'm using Picasso for some reasons.
In this case, I need to load the drawable
using its URI and not its id.
To do that, here is my code:
uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+context.getPackageName()+"/drawable/" + drawableName);
where drawableName used here are file names rather than their resource ids.
Then
Picasso.with(context).load(uri).into(imageView);
I know for sure that drawable name is correct, but Picasso seems it does not like this uri.
As mentioned in the documentation of Picasso .
they are now supporting loading Image from URI like the following :
so you have to do something like the following :
just like what you are doing already .
Hopethat helps .
If the images is in your drawable folder then you can just load it.
and picasso will load it no need for an Uri.
From picasso v2+ here is a big modification. The new version is very helpful for manage image cache data. It's using Singleton Instance.
GRADLE
Set drawable image
Bonus, get drawable by name:
You can load local image files from your drawable folder lazily if you know the integer value of the image that you want to be loaded.
Then you can just do:
Where
is the view you wish to display the image. For example:
And where
is the integer value of the drawable. You can retrieve this integer value by:
as well as
is the name of the drawable you want to draw (i.e. "ic_launcher")
THIS CAN ALL BE DONE INSIDE FROM THE ADAPTER
Found the answer. Unfortunately, Picasso do not allow drawable loading via URI. It is an incoming feature.