开发者

How to get the response from a modal dialog?

开发者 https://www.devze.com 2022-12-18 04:44 出处:网络
I currently开发者_Go百科 have this: Builder yesandno = new AlertDialog.Builder(this); yesandno.setTitle(\"QuickResponse\");

I currently开发者_Go百科 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?


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!
    }
});


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号