这是我到目前为止:
自定义对象:
class ItemObject {
List<String> name;
List<String> total;
List<String> rating;
public ItemObject(List<ItemObject> io) {
this.total = total;
this.name = name;
this.rating = rating;
}
}
Run Code Online (Sandbox Code Playgroud)
调用适配器:
List<String> names, ratings, totals;
ItemObject[] io= new ItemObject[3];
io[0] = new ItemObject(names);
io[1] = new ItemObject(rating);
io[2] = new ItemObject(totals);
adapter = new ItemAdapter(Items.this, io);
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
假设上面看起来没问题,我的问题是如何设置ItemAdapter,它是构造函数,并从对象中解开三个List.然后,在getView中,分配以下内容:
每个匹配位置:
TextView t1 = (TextView) rowView.findViewById(R.id.itemName);
TextView t2 = (TextView) rowView.findViewById(R.id.itemTotal);
RatingBar r1 = (RatingBar) rowView.findViewById(R.id.ratingBarSmall);
Run Code Online (Sandbox Code Playgroud)
例如,数组"名称"中的位置0为t1.将数组"totals"中的0位置设置为t1.将数组"rating"中的0位置设置为r1.
编辑:我不希望有人写整个适配器.我只需要知道如何从自定义对象中解包列表,以便我可以使用这些数据.(在另一个问题中甚至没有提起或询问的东西)