【发布时间】:2017-02-08 08:28:36
【问题描述】:
我正在尝试制作左侧有购物车项目列表视图的活动,然后是中心侧的类别列表视图,然后是右侧的产品网格视图,我想这样做: 1.点击category listview上的item会过滤gridview上的产品 2. 点击商品gridview上的item会做另外一个功能,比如存入表格并显示在左侧的listview上
不知何故,我无法使 onclick 工作,它不是错误,但 onclick 没有发生任何事情。这是为什么?如果我只使用 1 个列表视图,它的工作原理。纯粹是我的代码错误还是我们不能在 1 个活动中放置多个 gridview/listview? onclick sn-p:
/* LIST BILL */
final ArrayList<Bill> list_bill = getListBill();
final ListView listview_bill = (ListView) findViewById(R.id.order_listing);
listview_bill.setAdapter(new BillListAdapter(this, list_bill));
listview_bill.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Bill mBill = list_bill.get(position);
int bill_id = mBill.getID();
Log.d(TAG, "click bill ID:"+bill_id);
}
});
private ArrayList getListBill()
{
SQLiteDatabase mydatabase = openOrCreateDatabase("posDb",MODE_PRIVATE,null);
Cursor resultSet = mydatabase.rawQuery("SELECT * FROM bills",null);
ArrayList<Bill> results = new ArrayList<Bill>();
if (resultSet.moveToFirst()) {
do {
Bill billsData = new Bill();
billsData.setID(resultSet.getInt(0));
billsData.set_bill_no(resultSet.getString(1));
billsData.set_type(resultSet.getString(2));
billsData.set_table(resultSet.getString(3));
billsData.set_qty(resultSet.getInt(4));
billsData.set_amount(resultSet.getString(5));
billsData.set_status(resultSet.getString(6));
//put them into results
results.add(billsData);
} while (resultSet.moveToNext());
}
return results;
}
适配器代码(其中 3 个具有相似的适配器,因此我包括其中一个)
public class BillListAdapter extends BaseAdapter {
private ArrayList<Bill> listData;
private LayoutInflater layoutInflater;
public BillListAdapter(Context aContext, ArrayList<Bill> listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(aContext);
}
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_bill_layout, null);
holder = new ViewHolder();
//holder.txtBillNo = (TextView) convertView.findViewById(R.id.txtBillId);
holder.txtBillNo = (TextView) convertView.findViewById(R.id.txtBillNo);
holder.txtBillType = (TextView) convertView.findViewById(R.id.txtBillType);
holder.txtBillTable = (TextView) convertView.findViewById(R.id.txtBillTable);
holder.txtBillQty = (TextView) convertView.findViewById(R.id.txtBillQty);
holder.txtBillAmount = (TextView) convertView.findViewById(R.id.txtBillAmount);
holder.txtBillStatus = (TextView) convertView.findViewById(R.id.txtBillStatus);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//holder.txtBillId.setText(listData.get(position).getID() +"");
holder.txtBillNo.setText(listData.get(position).get_bill_no());
holder.txtBillType.setText(listData.get(position).get_type());
holder.txtBillTable.setText(listData.get(position).get_table());
//holder.txtBillQty.setText(listData.get(position).get_qty());
holder.txtBillAmount.setText(listData.get(position).get_amount());
holder.txtBillStatus.setText(listData.get(position).get_status());
return convertView;
}
static class ViewHolder {
//TextView txtBillId;
TextView txtBillNo;
TextView txtBillType;
TextView txtBillTable;
TextView txtBillQty;
TextView txtBillAmount;
TextView txtBillStatus;
}
}
【问题讨论】: