[英]Data-binding generic list in recyclerview
I would like to reuse the same fragment (that contains a RecyclerView) to show different lists: 我想重用相同的片段(包含一个RecyclerView)以显示不同的列表:
List<Pizze>, List<Pasta>, List<Wine>.
List <Pizze>,List <Pasta>,List <Wine>。
Let's consider that i have this 3 objects (Pizze,Pasta,Wine)and all those objects have the same fields: name and price. 让我们考虑一下,我有这3个对象(Pizze,Pasta,Wine),并且所有这些对象都具有相同的字段:名称和价格。 This RecyclerView in the fragment should show only those two fields: name and price for every list.
片段中的此RecyclerView应该仅显示这两个字段:每个列表的名称和价格。 In the layout i have to express the variable type:
在布局中,我必须表示变量类型:
variable name="items" type="List<Pizza>
变量名称=“ items”类型=“ List <Pizza>
How can i pass a generic list here? 如何在此处传递通用列表?
一个对象数组怎么样,第一个是名称,第二个是价格。
Just use generics. 只需使用泛型即可。
private List<T> mItems;
public void setItems(List<T> items) {
mItems = items;
notifyDataSetChanged();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.