我从 Activity 开始:
adapter = new ItemAdapter(Items.this, items, totals);
setListAdapter(adapter);
现在这里是 ItemAdapter:
public class ItemAdapter extends ArrayAdapter<String> {
private final List<String> items;
private final List<String> totals;
private final Context context;
public ItemAdapter(Context context, List<String> items,
List<String> totals) {
super(context, R.layout.item_row_layout, items);
this.context = context;
this.items = items;
this.totals = totals;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater
.inflate(R.layout.item_row_layout, parent, false);
TextView t1 = (TextView) rowView.findViewById(R.id.itemName);
TextView t2 = (TextView) rowView.findViewById(R.id.itemTotal);
String s1 = items.get(position);
t1.setText(s1);
String s2 = totals.get(position);
t2.setText(s2);
return rowView;
}
}
现在我知道问题出在构造函数上,因为直到只允许我传递一个列表,而不是两个。还有另一种方法可以做到这一点吗?