Picasso load drawable resources from their URI
Found the answer. Unfortunately, Picasso do not allow drawable loading via URI. It is an incoming feature.
Picasso don't load images from drawable (Android)
Try using a integer array
int[] image_array = new int[] { R.drawable.aa12, R.drawable.acr,
R.drawable.ai_l96a1, etc };
And load using
Picasso.with(mContext).load(image_array[position]).placeholder(R.drawable.ic_stub).into(imageView);
Picasso library does not load Images from URI
Answered my own question
if(songObject.albumArtURI != null){
File f = new File(songObject.albumArtURI);
Picasso.with(viewHolder.albumArt.getContext())
.load(f)
.placeholder(R.drawable.grayalbumart)
.into(viewHolder.albumArt);
} else {
Picasso.with(viewHolder.albumArt.getContext())
.load(songObject.albumArtURI)
.placeholder(R.drawable.grayalbumart)
.into(viewHolder.albumArt);
}
Picasso 2.71828 load uri issue
find the problem, using implementation 'com.squareup.picasso:picasso:2.71828' instead of importing picasso aar file, that will fix the issue. Could you someone tell me what difference between implementation and importing aar file?
Getting Drawable with Picasso
ImageView imageView = findViewByID(R.id.imageview);
String url = "http://www.website.com/image.png";
Picasso.with(context).load(url).placeHolder(R.drawable.image).into(imageView);
XML in your Layout Resource
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
This will take the URL from the internet and place it into the ImageView.
It looks like you are in a adapter... So you can do something like this...
ImageView imageView = findViewByID(R.id.imageview);
String url = userList[position].photoId;
Picasso.with(context).load(url).placeHolder(R.drawable.image).into(imageView);
Side note: You don't NEED a placeholder. When your images are loading, the space where the imageview is will be white until the image loads.
Looking more at your code... this is wrong..
list.add(Item("Milk (Just for example)", "$1.99", setImg("img")))
list.add(Hotel("Banana", "$2.99", setImg("img")))
Should be something like this.
list.add(Item("Milk (Just for example)", "$1.99", "http://www.google.com/image.jpg"))
list.add(Hotel("Banana", "$2.99", "http://www.google.com/image.jpg"))
And then in your adapter do this.... (its in java.... does picasso support kotlin?)
override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
holder?.textTitle?.text = userList[position].title
holder?.textPrice?.text = userList[position].price
String url = userList[position].url
Picasso.with(context).load(url).placeHolder(R.drawable.image).into(photoView);
//holder?.photoView?.setImageResource(userList[position].photoId)
}
Picasso Load image from filesystem
Of course you can. Its actually pretty straight forward:
File f = new File("path-to-file/file.png");
or
File f = new File(uri);
Picasso.get().load(f).into(imageView);
also
Picasso.get().load(uri).into(imageView);
works
Related Topics
Creating a Dialogpreference from Xml
Setting a Maximum Width on a Viewgroup
Can't Handle Both Click and Touch Events Simultaneously
Android Emulator - Trouble Creating User Accounts
Okhttp Library - Networkonmainthreadexception on Simple Post
Action Bar Menu Item Text Color
5.1 Crash - a Taskdescription's Primary Color Should Be Opaque
How to Have 1 Firebase Database for 2 Apps with Different Package Names
Android UI Design: Supporting Multiple Screens
How to Test Boot_Completed Broadcast Receiver in Emulator
How to Create Multiple Pendingintents with the Same Requestcode and Different Extras
Query the Google Play Store for the Version of an App
How to Use Unicode in Android Resource