如何使用对话框中两个以上的按钮 [英] How to use more than two buttons in dialog box

查看:134
本文介绍了如何使用对话框中两个以上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AlertDialog,我可以使用两种类型的按钮,按钮的负面和正面按钮。但是,如果我想使用两个以上的按钮我需要做什么?
下面的程序无法正常工作。

  AlertDialog.Builder警报=新AlertDialog.Builder(
                        QuizActivity.this);
                alert.setTitle(测验结果);
                alert.setMessage(正确答案
                        + scoreMode.getCorrectAnswer()+\\ n
                        +错误答案:+ scoreMode.getWrongAnswer()
                        +\\ n+总分
                        + scoreMode.getScorePoint()+\\ n
                        +加分+ scoreMode.getBonusPoint());
                alert.setPositiveButton(保存结果
                        新DialogInterface.OnClickListener(){
                            公共无效的onClick(DialogInterface为arg0,
                                    INT ARG1){
                                showSaveResultDailog(scoreMode
                                        .getScorePoint());
                            }                        });
                alert.setNegativeButton(再玩一次
                        新DialogInterface.OnClickListener(){
                            公共无效的onClick(DialogInterface为arg0,
                                    INT ARG1){
                                意图I =新意图(QuizActivity.this,
                                        QuizOptionActivity.class);
                                startActivity(ⅰ);
                            }
                        });
                alert.setNegativeButton(返回到主菜单
                        新DialogInterface.OnClickListener(){
                            公共无效的onClick(DialogInterface为arg0,
                                    INT ARG1){
                                意图I =新意图(QuizActivity.this,
                                        HomeActivity.class);
                                startActivity(ⅰ);
                            }
                        });
                alert.show();


解决方案

您还可以通过 setNeutralButton设置第三个按钮(..)

AlertDialog 三个按钮是最大。如果你超越了你需要通过的setContentView使用对话框和设置自定义视图(view)。按照这种观点,你可以有任何内容:按钮,布局,窗口小部件

In AlertDialog , I can use two types of button, negative button and positive button. But If I want to use more than two buttons what I need to do? The following program Is not working ..

    AlertDialog.Builder alert = new AlertDialog.Builder(
                        QuizActivity.this);
                alert.setTitle("Quiz Result");
                alert.setMessage("Correct Answer: "
                        + scoreMode.getCorrectAnswer() + "\n"
                        + "Wrong Answer: " + scoreMode.getWrongAnswer()
                        + "\n" + "Total Score: "
                        + scoreMode.getScorePoint() + "\n"
                        + "Bonus Score: " + scoreMode.getBonusPoint());
                alert.setPositiveButton("Save result",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface arg0,
                                    int arg1) {
                                showSaveResultDailog(scoreMode
                                        .getScorePoint());
                            }

                        });
                alert.setNegativeButton("Play Again",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface arg0,
                                    int arg1) {
                                Intent i = new Intent(QuizActivity.this,
                                        QuizOptionActivity.class);
                                startActivity(i);
                            }
                        });
                alert.setNegativeButton("Back to Main Menu",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface arg0,
                                    int arg1) {
                                Intent i = new Intent(QuizActivity.this,
                                        HomeActivity.class);
                                startActivity(i);
                            }
                        });
                alert.show();

解决方案

You can also set the third button via setNeutralButton(..).

Three buttons on AlertDialog is max. If you go beyond that you need to use Dialog and set custom view via setContentView(view). In this View you can have whatever content: buttons, layouts, widgets.

这篇关于如何使用对话框中两个以上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆