相关疑难解决方法(0)

如何禁用AlertDialog内的按钮?跟进问题

我昨天问了这个问题(http://stackoverflow.com/questions/7392321/how-do-you-disable-a-button-inside-of-an-alertdialog)并相应地修改了我的代码...今天早上我跑了模拟器中的代码并收到了NPE.这是代码:

public void monster() {
        int playerint = settings.getPlayerInt();
        int monsterint = settings.getMonsterInt();



        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        alertbox.setMessage("You have Encountered a Monster");

        alertbox.setPositiveButton("Fight!",
                new DialogInterface.OnClickListener() {

                    // do something when the button is clicked
                    public void onClick(DialogInterface arg0, int arg1) {
                        createMonster();
                        fight();

                    }
                });

        alertbox.setNeutralButton("Try to Outwit",
                new DialogInterface.OnClickListener() {

                    // do something when the button is clicked
                    public void onClick(DialogInterface arg0, int arg1) {
                        // This should not be static
//                      createTrivia();
                        trivia();

                    }
                });

        // Return …
Run Code Online (Sandbox Code Playgroud)

android

-1
推荐指数
1
解决办法
4090
查看次数

标签 统计

android ×1