-2

how to make 2 arraylist on an adapter, adapted to one API. I have given a list of cases here metadataList; but it doesn't work because the activity.java part must have a Metadata List implementation. How to retrieve data with different getter setters (2 getter setters) but can be combined in one adapter?

API Result

{
    "status": 200,
    "reason": "OK",
    "success": true,
    "message": null,
    "result": [
        {
            "id": "1",
            "id_product_category": "2",
            "id_currency": "58",
            "name": "PlayStation 4 500GB Console - Refurbished",
            "slug": "playstation-4-500gb-console-refurbished",
            "image": "https://demo.xxxx.com/images/products/product-1.png",
            "images": [
                {
                    "name": "main",
                    "image": "https://demo.xxxx.com/storage/images/products/product-1.png"
                }
            ],
            "metadata": {
                "weight_value": "1",
                "weight": "KG",

            }
        }

ResultItem.java

public class ResultItem{

    @SerializedName("image")
    private String image;


    @SerializedName("images")
    private ImagesItem[] images;

    @SerializedName("metadata")
    private Metadata metadata;



    @SerializedName("id_product_category")
    private String idProductCategory;

    @SerializedName("price_capital")
    private String priceCapital;



    @SerializedName("name")
    private String name;

    @SerializedName("id")
    private String id;

    @SerializedName("id_currency")
    private String idCurrency;

    @SerializedName("slug")
    private String slug;

    public void setImage(String image){
        this.image = image;
    }

    public String getImage(){
        return image;
    }


    public void setImages(ImagesItem[] images){
        this.images = images;
    }

    public ImagesItem[] getImages(){
        return images;
    }

    public void setMetadata(Metadata metadata){
        this.metadata = metadata;
    }

    public Metadata getMetadata(){
        return metadata;
    }




    public void setIdProductCategory(String idProductCategory){
        this.idProductCategory = idProductCategory;
    }

    public String getIdProductCategory(){
        return idProductCategory;
    }

    public void setPriceCapital(String priceCapital){
        this.priceCapital = priceCapital;
    }

    public String getPriceCapital(){
        return priceCapital;
    }



    public void setPriceSale(String priceSale){
        this.priceSale = priceSale;
    }

    public String getPriceSale(){
        return priceSale;
    }


    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return name;
    }

    public void setId(String id){
        this.id = id;
    }

    public String getId(){
        return id;
    }

    public void setIdCurrency(String idCurrency){
        this.idCurrency = idCurrency;
    }

    public String getIdCurrency(){
        return idCurrency;
    }



}

Metadata.java

public class Metadata{


    @SerializedName("weight_value")
    private String weightValue;

    @SerializedName("weight")
    private String weight;





    public void setWeightValue(String weightValue){
        this.weightValue = weightValue;
    }

    public String getWeightValue(){
        return weightValue;
    }

    public void setWeight(String weight){
        this.weight = weight;
    }

    public String getWeight(){
        return weight;
    }


}

Adapter.java

public class AdapterAllProduct extends RecyclerView.Adapter<AdapterAllProduct.AllproductHolder> {

   List<ResultItem> resultItemList;
  //// List<Metadata> metadataList;
   Context mContext;

    public AdapterAllProduct(Context context, List<ResultItem> resulList){
        this.mContext = context;
        resultItemList = resulList;
    }

    @NonNull
    @Override
    public AllproductHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_product, parent,false);
        return new AllproductHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull AllproductHolder holder, int position) {
        final ResultItem resultItem = resultItemList.get(position);
        ///final Metadata metadataItem = metadataList.get(position);
        holder.txt_id.setText(resultItem.getId());
        holder.txt_id_currency.setText(resultItem.getIdCurrency());
        holder.txt_id_product_category.setText(resultItem.getIdCurrency());
        holder.txt_name_product.setText(resultItem.getName());
        holder.txt_price_capital.setText(resultItem.getPriceCapital());
//        Locale localeID = new Locale("in", "ID");
//        NumberFormat formatRupiah = NumberFormat.getCurrencyInstance(localeID);
//        holder.txt_price_capital.setText(formatRupiah.format(resultItem.getPriceCapital()));
        holder.txt_price_sale.setText(resultItem.getPriceSale());
        holder.txt_description.setText(resultItem.getDescription());
        holder.txt_sku.setText(resultItem.getSku());
        holder.txt_stock.setText(resultItem.getStock());
        //holder.image.setText(resultItem.getImage());
        holder.txt_condition.setText(resultItem.getCondition());
        holder.txt_deliverable.setText(resultItem.getDeliverable());
        holder.txt_downloadable.setText(resultItem.getDownloadable());
        holder.txt_target_gender.setText(resultItem.getTargetGender());
        holder.txt_target_age.setText(resultItem.getTargetAge());
        holder.txt_visibility.setText(resultItem.getVisibility());
        holder.txt_image.setText(resultItem.getImage());
        Glide.with(mContext)
                .load(resultItem.getImage())
                .placeholder(R.drawable.no_image)
                .error(R.drawable.no_image)
                .into(holder.image);

//        holder.txt_weight_value.setText(metadataItem.getWeightValue());
//        holder.txt_weight.setText(metadataItem.getWeight());

        final String id = resultItem.getId();
        final String id_currency = resultItem.getIdCurrency();
        final String id_product_category = resultItem.getIdProductCategory();
        final String name = resultItem.getName();
        final String description = resultItem.getDescription();
        final String stock = resultItem.getStock();
        final String price_capital = resultItem.getPriceCapital();
        final String price_sale = resultItem.getPriceSale();
        final String condition = resultItem.getCondition();
        final String image = resultItem.getImage();
//        final String weight_value = metadataItem.getWeightValue();
//        final String weight = metadataItem.getWeight();

        holder.btnclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent detailproduct = new Intent(v.getContext(), DetailProduct.class);
                detailproduct.putExtra("id", id);
                detailproduct.putExtra("id_product_category", id_product_category);
                detailproduct.putExtra("id_currency", id_currency);
                detailproduct.putExtra("name", name);
                detailproduct.putExtra("price_capital", price_capital);
                detailproduct.putExtra("price_sale", price_sale);
                detailproduct.putExtra("description", description);
                detailproduct.putExtra("stock", stock);
                detailproduct.putExtra("condition", condition);
                detailproduct.putExtra("image", image);
//                detailproduct.putExtra("weight_value", weight_value);
//                detailproduct.putExtra("weight", weight);
                v.getContext().startActivity(detailproduct);
            }
        });


    }

1 Answers1

0
public class AdapterAllProduct extends RecyclerView.Adapter<AdapterAllProduct.AllproductHolder> {



.......

        holder.txt_weight_value.setText(resultItem.getMetadata().getWeightValue());
.......

        holder.btnclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

....... detailproduct.putExtra("weight_value", weight_value); .....