Android alert dialog and set positive button

前端 未结 3 1562
無奈伤痛
無奈伤痛 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:34
    AlertDialog.Builder builder = new AlertDialog.Builder(your_activity.this);
    builder.setTitle(!puzzle.isSolved() ? R.string.title_stats : stats.isNewBest() ? R.string.title_new_record : R.string.title_solved);
    builder.setMessage(msg);
    builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            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);
         }
    });
    builder.show();
    

    try this

    0 讨论(0)
  • 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();
    
    0 讨论(0)
  • 2021-01-02 09:56

    Add following code to show the dialog.

    AlertDialog alert = builder.create();
    alert.show();
    
    0 讨论(0)
提交回复
热议问题