AlertDialog button doesn't work and it doesn't dismiss

后端 未结 2 1180
粉色の甜心
粉色の甜心 2021-01-29 10:46

I have this AlertDialog that should be a duel between two players. It shows an image of a duel and after three seconds, thanks to a timer, it shows a \"BANG\" image. When the \"

相关标签:
2条回答
  • 2021-01-29 11:29

    Use this alert box. Its work for me

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SettingActivity.this);
                    alertDialogBuilder.setMessage("Message");
    
                    alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            //Code
                            dialog.cancel();
                        }
                    });
    
                    alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
    
                    AlertDialog alertDialog = alertDialogBuilder.create();
                    alertDialog.show();
    
    0 讨论(0)
  • 2021-01-29 11:30

    You need to call the showDialog(int)method. Then override the method onCreateDialog(int) inside this create the dialog and set the positive and negative buttons and then it will work.

    Though this way is deprecated. You should use fragments now. But still you can give it a try!
    Check this link: https://developer.android.com/guide/topics/ui/dialogs.html

    0 讨论(0)
提交回复
热议问题