Unable to fetch data from Custom Adaptor in android

83 Views Asked by At

I have created a list of Products which are correctly populating in the CustomListAdaptor that I created but the View is not getting rendered when I am running the application.

In the below Adaptor, prodList is correctly getting populated as a Product entity

import android.app.Activity;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;


public class CustomProductListAdaptor extends ArrayAdapter {

    //to reference the Activity
    private final Activity context;

    private final List<Product> productList;


    public CustomProductListAdaptor(Activity context,List<Product> prodList){
        super(context,R.layout.productlist_item);
        this.context=context;
        this.productList = prodList;
    }

    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater=context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.productlist_item, null,true);
        Toast.makeText(getContext(),"In getView",Toast.LENGTH_LONG).show();

        //this code gets references to objects in the listview_row.xml file
        TextView nameTextField = (TextView) rowView.findViewById(R.id.product_name);
        TextView priceTextField = (TextView) rowView.findViewById(R.id.product_description);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.productImage);

        //this code sets the values of the objects to values from the list
        try {
            nameTextField.setText(productList.get(position).getName());
            priceTextField.setText(productList.get(position).getPrice()+"/-");
            Uri imageUri = Uri.parse(productList.get(position).getImgUrl());
            Picasso.with(context).load(imageUri).placeholder(R.drawable.selectphoto).into(imageView);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rowView;
    }


}
1

There are 1 best solutions below

7
moumenShobakey On

set the item view layout height to wrapcontent

set a layoutmanager to the recyclerview