Hajar Ammoumri
Hajar Ammoumri

Reputation: 65

Android How to disable a positive button after click

I have an information popup which has 2 buttons : Negative (Cancel) and Positive (Continue). How can i disable the positive button after a click. The Click on the button generates a file. It calls a function that is quite heavy, so it takes time to close the popup. I am doing this to prevent the user to click twice and thus generate two files.

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();
            }

        });

Thanks a lot for your help! :)

Upvotes: 1

Views: 580

Answers (2)

Haniyeh Khaksar
Haniyeh Khaksar

Reputation: 804

use this code:

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

see this link

Upvotes: 0

Seshu Vinay
Seshu Vinay

Reputation: 13588

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

Upvotes: 1

Related Questions