I have text in the model. Must carry adapter. public int cid = -1; public String category_name; I want to transfer text only to the adapter. When I transfer some errors occur.I have tried to transfer from text model many times in adapter but I am not getting text i am new devloper How to fix this error
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.kannada.newspaper.india.R;
import com.kannada.newspaper.india.activities.MainActivitym;
import com.kannada.newspaper.india.model.Category;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
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());
// //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 model
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;
}
}
layout
<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:alpha="1"
android:background="@drawable/bg_roundiconimg"
android:gravity="center"
android:orientation="vertical">
<!-- <ImageView-->
<!-- android:id="@+id/photo"-->
<!-- android:layout_width="60dp"-->
<!-- android:layout_height="60dp"-->
<!-- android:layout_gravity="center" />-->
</LinearLayout>
<TextView
android:id="@+id/name"
android:layout_width="347dp"
android:layout_height="263dp"
android:layout_marginTop="@dimen/margin10"
android:fontFamily="@font/sfprodisplayregular"
android:text="Facebook"
android:textColor="@color/colorWhite"
android:textSize="@dimen/primeryText" />
</LinearLayout>
</com.kannada.newspaper.india.utils.SquareFrameLayout>
>Solution :
You are doing wrong you have to get the value from models not from the textview as in your sample you are doing below
TextView prdId = view.findViewById(R.id.name);
prdId.setText(prdId.toString());
you need to get the value from the model like below
prdId.setText(mensWears.get(i).getItemName());