Android如何在单击后禁用正面按钮

时间:2016-03-23 11:03:04

标签: android button android-alertdialog builder

我有一个信息弹出窗口,其中有2个按钮:Negative(取消)和Positive(Continue)。如何在单击后禁用正按钮。 单击按钮生成一个文件。它调用的函数非常繁重,因此关闭弹出窗口需要时间。我这样做是为了防止用户点击两次,从而生成两个文件。

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.close_tour_tour_not_collected);
        builder.setItems(items, null);
        builder.setPositiveButton(R.string.common_continue, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface arg0,
                    int arg1) {     
                    // How to disable the button after the click??? 
                    saveTourAndCloseActivity();
            }

        });

非常感谢你的帮助! :)

2 个答案:

答案 0 :(得分:1)

(Dialog.class.cast(arg0)).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

答案 1 :(得分:0)

使用此代码:

((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

请参阅此link