当用户选择要删除的项目时,我会打开一个 alertDialog 以确保他想要删除它。当我获得 BUTTON_POSITIVE 的 onClick 时,我需要获取要删除的文件名。这在打开 alertDialog 之前是已知的。我尝试使用 setButton(BUTTON_POSITIVE, "Yes", msg) 并在消息中设置文件名,但我不清楚从哪里得到消息?有人可以澄清或提出更好的实施吗?
这是单击删除按钮后运行的代码:
public void OnClick(View v)
{
Button b = (Button)v;
CharSequence cs = b.getText();
int id = Integer.parseInt(cs.toString());
AlertDialog alertDialog;
Message msg = new Message();
msg.arg1 = id;
AlertDialog deleteAlert = new AlertDialog.Builder(this).create();
deleteAlert.setTitle("Trigger Remove Alert");
deleteAlert.setMessage("Are you sure you want to remove this trigger?");
deleteAlert.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", msg);
deleteAlert.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//remove Trigger
//boolean b = RemoveTriggerPOI(aid, id);
}
});
deleteAlert.setButton2("No", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//...
}
});
deleteAlert.show();
}