Not being able to get image from URL and insert it into Recycler view

37 Views Asked by At

I'm working on a project where we receive a link to an image and we're supposed to use it as an "icon" to a specific recycler view Item. I'm trying to use Picasso to get this done but It's not working. I have verified that the link is working.

This is my onBindViewHolder, where I'm using Picasso:

public void onBindViewHolder(final TrailViewHolder holder, int position) {
        Trail t = mTrails.get(position);
        holder.mTrailName.setText(t.getTrail_name());
        holder.mTrailDesc.setText(t.getTrail_description());
        //Get image
        Picasso.get().load(t.getImage_src())
                     .placeholder(R.drawable.no_image)
                     .into(holder.mTrailImage);


}

I used placeholder() to make sure that the code was working and was in fact adding the image to the recycler view item, which it does.
The t.getImage_src() method returns a string with the link to the required image.

These are the permissions I've included in my android manifest:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

Is there any step that I'm missing?

1

There are 1 best solutions below

4
phanz On

You can use Picasso.with(Context).setLoggingEnabled(true) to enable debugging so as to troubleshoot the exact cause . If the log has something like Error 504 try using:

android:usesCleartextTraffic="true"

in Application tag of your manifest.