我试图在 2 个活动之间传输数据,然后使用适配器显示。早些时候我使用相同的适配器来显示列表,但这在我的适配器中产生了几个错误,我在下面的代码中显示了它们。
谁能弄清楚我应该怎么做才能纠正它。任何帮助,将不胜感激。
通过这些细节的第一个活动,
intent.putExtra("quantity", quantity);
intent.putExtra("instructions", instructions);
intent.putExtra("subTotal", subTotal);
intent.putExtra("description", description);
intent.putExtra("price", price);
第二次活动
String quantity = getIntent().getStringExtra("quantity");
String description = getIntent().getStringExtra("description");
String subTotal = getIntent().getStringExtra("subTotal");
String price = getIntent().getStringExtra("price");
CustomGridPastaCart adapter = new CustomGridPastaCart(getApplicationContext(),
quantity, description, subTotal, price); //error2
CustomGridPastaCart、BaseAdapter
public class CustomGridPastaCart extends BaseAdapter {
private Context context;
List<Item> items;
public CustomGridPastaCart(Context c, List<Item> items) {
this.items = items;
}
public CustomGridPastaCart(Context applicationContext, String quantity, //it was forcing me to generate this error2 in above
String description, String subTotal, String price) {
// TODO Auto-generated constructor stub
}
@Override
public int getCount() {
return items.size();
}
@Override
public Item getItem(int position) { //here i had to change object to Item because it gave an error1 in below
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.cart_activity, parent, false);
holder.tvHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
holder.tvUnitprice = (TextView) convertView
.findViewById(R.id.lbl_unitprice);
holder.tvQty = (TextView) convertView.findViewById(R.id.lbl_qty);
holder.ivSubtotal = (TextView) convertView
.findViewById(R.id.lblsubtotal);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// Get item...
Item item = getItem(position); //error1 here
// Set values.
holder.tvHeader.setText(item.description);
holder.tvUnitprice.setText(item.price);
holder.tvQty.setText(item.quantity);
holder.ivSubtotal.setText(item.subTotal);
return convertView;
}
private class ViewHolder {
private TextView tvHeader;
private TextView tvUnitprice;
private TextView tvQty;
private TextView ivSubtotal;
} }
项目.java
public class Item {
String quantity;
String description;
String subTotal;
String price;
}