tags:

views:

80

answers:

2

I currently have this:

Builder yesandno = new AlertDialog.Builder(this);           
yesandno.setTitle("QuickResponse");
yesandno.setMessage(message);
yesandno.setPositiveButton("YES", null);
yesandno.setNegativeButton("NO", null);
yesandno.show();

How should I go by setting an event listener that will capture if the user clicked YES or NO?

+6  A: 

When you call setPositiveButton() and setNegativeButton() instead of passing in null you should pass in a DialogInterface.OnClickListener.

For example:

yesandno.setPositiveButton("YES", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        //User clicked yes!
    }
});
Dave Webb
+4  A: 

Just do something like:

yesandno.setPositiveButton("YES", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        // User clicked yes
    }
});
yesandno.setNegativeButton("NO", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        // User clicked no
    }
});

and do whatever you want in the button callbacks.

Erich Douglass