I’m making a program that takes data input from a realtime database, but when I try to show the image via the link and picasso, it doesn’t seem to work. The application starts, there are no crashes but the image is not displayed.
This is the code of the ListAdapter class
public class ListAdapter extends ArrayAdapter<Item> {
private int resourceLayout;
private Context mContext;
public ListAdapter(Context context, int resource, List<Item> items) {
super(context, resource, items);
this.resourceLayout = resource;
this.mContext = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(mContext);
v = vi.inflate(resourceLayout, null);
}
Item p = getItem(position);
if (p != null) {
ImageView im1 = (ImageView) v.findViewById(R.id.itemLogo);
TextView tt2 = (TextView) v.findViewById(R.id.itemName);
TextView tt3 = (TextView) v.findViewById(R.id.itemDescription);
if (im1 != null) {
Picasso.get().load(p.getLogo()).fit().centerCrop().into(im1); //getLogo
}
if (tt2 != null) {
tt2.setText(p.getName() + " - " + p.getPrice() + " D");
}
if (tt3 != null) {
tt3.setText(p.getDescription());
}
}
return v;
}
This is the design of the list adapter
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
>
<ImageView
android:id="@+id/itemLogo"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Item Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="20sp"
android:id="@+id/itemName"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="15sp"
android:id="@+id/itemDescription"
/>
</LinearLayout>
Is it possible somehow to solve this problem?
I don’t think the problem is the link but in case this is what I used in the tests : https://it.cleanpng.com/png-4816az/preview.html
You need to debug and add 2 breakpoints
1st on line if(im1 != null)
and second on the inside statement of this if-block.
1st breakpoint will help you to check if im1
is initialized properly, second will help you to see the value/path returned by p.getLogo()
Try to copy and open the path in a browser to see this path really leads to the image.