Search code examples
androidandroid-layoutpicasso

Picasso doesn't load drawable image into ImageView


Picasso can't load image drawable into ImageView, I've tried to change ImageView's width and height, resizing image, loading it with and without fit(), resize() or center() and image is stil not visible. I am using Picasso at whole project, and everywhere works fine, but it gives no result at this one.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainFullFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/mainThemeBlack"
    tools:context=".MainTabsActivity">



    <RelativeLayout
        android:id="@+id/rlSynchroView"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:background="@color/bottom_sheet_blue">
        <TextView
            android:id="@+id/tvSynchroLast"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:layout_marginEnd="10dp"
            android:textColor="@color/mdtp_white"
            android:text="Last synchro: 10:38"/>



        <ImageView
            android:id="@+id/ivSynchroIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tvSynchroLast"
            android:elevation="5dp"/>
    </RelativeLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/listFullView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:dividerHeight="10.0sp"
        android:layout_above="@id/rlSynchroView"
        android:background="?android:attr/selectableItemBackground"
        android:divider="@color/mainThemeBlack"
        android:paddingBottom="70dp"
        android:clipToPadding="false">

    </android.support.v7.widget.RecyclerView>
</RelativeLayout>

Method call:

Picasso.get().load(R.drawable.refresh_icon)
                .resize(10, 10)
                .into(refreshIV);

I am calling it inside onViewCreated() and I've tried to resize it with different values too.

I want to achieve clickable bottom bar with refresh icon (and info about time of last synchro), to synchronize data with service inside onClick method

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        mView = inflater.inflate(R.layout.list_full, container, false);

        refreshIV = mView.findViewById(R.id.ivSynchroIcon);

        mobileArray = new ArrayList<IssuePOJO>(); 
        dbStats.open();

        generateList();

        mView = view;
        return mView;

    }

Solution

  • Picasso syntax looks correct, but looks like onCreateView method logic is incorrect

    Please try with below code:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.list_full, container, false);
    
        refreshIV = mView.findViewById(R.id.ivSynchroIcon);
    
        mobileArray = new ArrayList<IssuePOJO>(); 
        dbStats.open();
    
        generateList();
    
        //mView = view;//please comment this one and try
        return mView;
    
    }