Android alert dialog and set positive button

前端 未结 3 1581
無奈伤痛
無奈伤痛 2021-01-02 09:33

This is for a slider puzzle. I want to show a dialog box with OK button when the puzzle is completed. When the OK button is pressed, I use an Intent to load a w

3条回答
  •  长发绾君心
    2021-01-02 09:35

    Check the below code. It may help you

    AlertDialog alertDialog = new AlertDialog.Builder(
                    GeneralClassPhotoCaptureImageVideo.this).create(); // Read
                                                                        // Update
            alertDialog.setTitle("Title of dialog");
            alertDialog
                    .setMessage("contents");
            alertDialog.setButton(Dialog.BUTTON_POSITIVE, "Ok",
                    new DialogInterface.OnClickListener() {
    
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
                          Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www..com"));
        Bundle b = new Bundle();
        b.putBoolean("new_window", true); //sets new window
        intent.putExtras(b);
        startActivity(intent);
                        }
    
    
                    });
            alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "Cancel",
                    new DialogInterface.OnClickListener() {
    
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
    
    
                        }
                    });
            alertDialog.show();
    

提交回复
热议问题