When a user selects an item to delete, I open an alertDialog to make sure he wants to delete it. When I get the onClick for BUTTON_POSITIVE I need to get the file name to delete. This was known before opening the alertDialog. I tried using setButton(BUTTON_POSITIVE, “Yes”, msg) and set the file name in the message but it is not clear to me where do I get the message? Can someone clarify or propose a better implementation?
Here’s the code that runs after clicking the delete button:
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();
}
First, define your
idorcsas:Now simply use
csandidinside the dialog button’s onClick listener: