Android alert dialog and set positive button

前端 未结 3 1564
無奈伤痛
無奈伤痛 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

提交回复
热议问题