java - 在 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 {
}
}
解决方案
推荐阅读
- html - 使图像适合父级并在其上添加铭牌
- html - 如何用css添加第二个背景?
- sql - postgres 仅在不存在时创建用户
- great-expectations - 对流数据使用很高的期望
- python - Django未检测模型中的日期时间字段
- visual-studio - 将变量从 Fortran DLL 传递到主程序的问题
- node.js - Dockerfile 中 nats-server 的 CMD 命令是什么
- java - 有没有办法从另一个 Android 应用程序读取来自 Facebook Messenger 的消息?
- r - x轴名称和颜色变化
- javascript - 如何使用 javascript/Jquery 在通知托盘中显示我的音乐播放器网站的媒体控件?