不推荐使用AlertDialog setButton

Ata*_*erk 4 eclipse android

我在Eclipse Android项目中使用了这段代码

alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
});
Run Code Online (Sandbox Code Playgroud)

但Eclipse说:

此方法在API级别3中已弃用.对BUTTON_POSITIVE使用setButton(int,CharSequence,android.content.DialogInterface.OnClickListener)

Opr*_*day 19

AlertDialog alert = new AlertDialog.Builder(this).create();
            alert.setTitle("Error");
            alert.setMessage("Sorry, your device doesn't support flash light!");
            alert.setButton(Dialog.BUTTON_POSITIVE,"OK",new DialogInterface.OnClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });

alert.show();
Run Code Online (Sandbox Code Playgroud)