How to pass adapter image from model category?

Viewed 28

How to transfer image from category model to adapter **public String category_image;**Only these should be taken to the adapter. I have tried many times and I am getting many errors.I have given the image below.The error in them should be corrected i am new android devloper enter image description here

category model this

    import java.io.Serializable;

public class Category implements Serializable {

    public int cid = -1;
    public String category_name;
    public String category_image;
    public String recipes_count;

    public Category(String name, String profession, int photo) {
    }


    public String getItemName() {
        return this.category_name;
    }


    public String category_image() {
        return this.category_image;
    }
}

public class GalleryAdapter extends BaseAdapter { private Context context;

private List<Category>  mensWears;


public GalleryAdapter(Context context, List<Category> mensWears) {
    this.context = context;
    this.mensWears = mensWears;
}

@Override
public int getCount() {
    return mensWears.size();
}

@Override
public Object getItem(int i) {
    return null;
}

@Override
public long getItemId(int i) {
    return 0;
}

@Override
public View getView(int i,View view,ViewGroup viewGroup) {
    final Category mensWear = mensWears.get(i);

    if (view == null) {
        final LayoutInflater layoutInflater = LayoutInflater.from(context);
        view = layoutInflater.inflate(R.layout.custom_gallery_layout, null);
    }
    //For text
    TextView prdId = view.findViewById(R.id.name);
   //        prdId.setText(prdId.toString());
    Picasso.get()
            .load(getApiUrl + "/upload/category/" + mensWears.category_image)
            .placeholder(R.drawable.ic_thumbnail)
            .into(i.category_image);


    prdId.setText(mensWears.get(i).getItemName());


//        //For images
//        final ImageView imageView = view.findViewById(R.id.name);
//        if(!TextUtils.isEmpty(mensWear.getItemName())){
//
////            Picasso.with(context).load(imageUrlFromServer+mensWear.category_image())
 ////                    .into(imageView);

    return view;
}

this adapter layout

 <?xml version="1.0" encoding="utf-8"?>
   <com.kannada.newspaper.india.utils.SquareFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/ll_main"
    android:padding="@dimen/nav_header_vertical_spacing"
    android:orientation="vertical">

    <ImageView
        android:background="@drawable/bg_google"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:gravity="center"
            android:alpha="1"
            android:orientation="vertical">
            <ImageView
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_gravity="center"
                android:id="@+id/photo"/>
        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/colorWhite"
            android:textSize="@dimen/primeryText"
            android:fontFamily="@font/sfprodisplayregular"
            android:layout_marginTop="@dimen/margin10"
            android:id="@+id/name"
            android:text="Facebook"/>
    </LinearLayout>

</com.kannada.newspaper.india.utils.SquareFrameLayout>
1 Answers

First, you need to get the view from the XML

ImageView imageView = view.findViewById(R.id.name);

Then you need to set the data and imageview in Picasso like

 Picasso.get()
            .load(getApiUrl + "/upload/category/" + mensWears.get(i).category_image())
            .placeholder(R.drawable.ic_thumbnail)
            .into(imageView);
Related