首页 > 解决方案 > 在 RecycleView、Java Android 中引用另一个 Object 列表

问题描述

我使用改造来获得 Json 对象的响应。

我有 2 节课:

public class Product {
    private String token;
    @SerializedName("id_prodotto")
    private int productId;
    @SerializedName("id_testuale")
    private  String productTextId;
    @SerializedName("nome_prodotto")
    private String productName;
    @SerializedName("descrizione_prodotto")
    private String productDesc;
    @SerializedName("prezzo_prodotto")
    private String productPrice;
    @SerializedName("tipo_prodotto")
    private String productType;
    .........
}

public class ProductCategories {
    @SerializedName("id")
    private int productCategoryId;
    @SerializedName("nome_categoria")
    private String ProductCategoryName;
}

我创建RecycleView并获得了产品。我的问题是获取参考,例如:

if productType is 1;
get ProductCategoryName where productCategoryId is 1;


     productsList2 = all.getProducts();
                prodCat = all.getProductCategories();
                recyclerViewProdotti.setLayoutManager(new 
     LinearLayoutManager(getContext()));
                recyclerViewProdotti.setHasFixedSize(true);
                adapterProducts = new AdapterProducts(context.getApplicationContext(), 
     productsList2, tkn,prodCat);

在不工作的适配器中循环 - 我的适配器:

    @Override
    public void onBindViewHolder(@NonNull  AdapterProducts.ViewHolder holder, int position) {
        holder.nome.setText(itemsfull.get(position).getProductName());
        holder.price.setText("€" + itemsfull.get(position).getProductPrice());
        
        itemsProdType = new ArrayList<>();
        int catProd = itemsfull.get(position).getProductCat();
        for (int i = 0; i < itemsProdType.size(); i++) {
           int id = itemsProdType.get(i).getProductCategoryId();
            if (id == catProd){
                holder.type.setText(itemsProdType.get(i).getProductCategoryName());
            }else {
                
            }
        }

标签: javaandroid-studioandroid-recyclerview

解决方案


推荐阅读