Alternative setButton

2020-05-25 06:48发布

I use this code in my android project:

alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });

But, Eclipse says that setButton() is deprecated. Please, help me with an alternative solution. Thanks!

标签: android
8条回答
看我几分像从前
2楼-- · 2020-05-25 07:21
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle("ALERTTILESTRING")
        .setMessage("alertNameString")
        .setCancelable(false)
        .setNegativeButton("Close",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

I hope the above code is a good one in which dialog works very well

查看更多
够拽才男人
3楼-- · 2020-05-25 07:23

Use: setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener);

For whichButton use one of the following:

DialogInterface.BUTTON_POSITIVE 
DialogInterface.BUTTON_NEGATIVE
DialogInterface.BUTTON_NEUTRAL 
查看更多
登录 后发表回答