1

当用户选择要删除的项目时,我会打开一个 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();



}
4

1 回答 1

0

首先,将您的idor定义cs为:

final int id = Integer.parseInt(cs.toString());
final CharSequence cs = b.getText();

现在只需在对话框按钮的onClick侦听器中使用csand :id

 deleteAlert.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener(){

    @Override
    public void onClick(DialogInterface dialog, int which) {               
       //remove Trigger
       //boolean b = RemoveTriggerPOI(aid, id);

       //SIMPLY USE id OR cs HERE. IT SHOULD WORK
    }
    });
于 2012-04-11T07:09:33.143 回答