这是一个带有 AlertDialog 的 ListView,用于 Bills 应用程序,当单击每个列表项时,它会弹出支付、编辑或删除选项。然后您选择“支付”或“编辑”,然后在重定向到另一个活动之前收集该选项的相应数据。when delete is selected a different AlertDialog appears for confirmation before deleting.
我有这个工作得很好(listView 项目是可点击的),但现在什么都没有。我一遍又一遍地检查我的代码,我被难住了。我敢肯定它最终会变得很小,但对于我的生活,我无法弄清楚。
谁能告诉我我在这里缺少什么?
final Context context = this;
ArrayList<BillArray> bills = db.getBillArray();
final ListView lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new MyCustomBaseAdapter(this, bills));
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv.getItemAtPosition(position);
final BillArray fullObject = (BillArray)o;
Toast.makeText(MainActivity.this, "You've chosen: "+" "+ fullObject.getVendor(),
Toast.LENGTH_SHORT).show();
final CharSequence[] items = { "Pay Bill", "Edit", "Delete" };
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Options for:\n"+ fullObject.getVendor());
builder.setIcon(R.drawable.ic_launcher);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item] + " selected",
Toast.LENGTH_SHORT).show();
if(items[item] == "Pay Bill"){
// LOAD "PAY BILL" PAGE
Intent payBill = new Intent(context, PayBillActivity.class);
payBill.putExtra("id", fullObject.getId());
payBill.putExtra("vendor", fullObject.getVendor());
payBill.putExtra("acct", fullObject.getAcct());
payBill.putExtra("payment", fullObject.getPayment());
payBill.putExtra("mindue", fullObject.getMinDue());
payBill.putExtra("tDue", fullObject.getTdue());
payBill.putExtra("tBal", fullObject.getTbal());
final int result = 1;
startActivityForResult(payBill, result);
}
if(items[item] == "Edit"){
// LOAD "EDIT" PAGE
Intent editBill = new Intent(context, EditBillActivity.class);
editBill.putExtra("id", fullObject.getId());
editBill.putExtra("vendor", fullObject.getVendor());
editBill.putExtra("acct", fullObject.getAcct());
editBill.putExtra("payment", fullObject.getPayment());
editBill.putExtra("typePos", fullObject.getTypePos());
editBill.putExtra("billType", fullObject.getBillType());
editBill.putExtra("billDay", fullObject.getBillDay());
editBill.putExtra("mindue", fullObject.getMinDue());
editBill.putExtra("amtPaid", fullObject.getAmtPaid());
editBill.putExtra("tDue", fullObject.getTdue());
editBill.putExtra("tBal", fullObject.getTbal());
final int result = 1;
startActivityForResult(editBill, result);
}
if(items[item] == "Delete"){
// POP-UP CONFIRMATION DIALOG W/ "DELETE" AND "CANCEL" BUTTON
AlertDialog.Builder delCon = new AlertDialog.Builder(MainActivity.this);
delCon.setTitle("DELETE " + fullObject.getVendor() + "?");
delCon.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.deleteBill(fullObject);
Toast.makeText(getApplicationContext(), "DELETED",
Toast.LENGTH_LONG).show();
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
delCon.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "DELETION CANCELLED",
Toast.LENGTH_LONG).show();
}
});
AlertDialog confirm = delCon.create();
confirm.show();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});