1

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! :)

  • 1
    Possible duplicate of [How to disable / enable dialog negative positive buttons?](http://stackoverflow.com/questions/8238952/how-to-disable-enable-dialog-negative-positive-buttons) – Aditya Vyas-Lakhan Mar 23 '16 at 11:07
  • Just block the saveTourAndCloseActivity() method inside onclick() after clicking – oshurmamadov Mar 23 '16 at 11:08
  • i hope your answer below link: [http://stackoverflow.com/questions/8238952/how-to-disable-enable-dialog-negative-positive-buttons](http://stackoverflow.com/questions/8238952/how-to-disable-enable-dialog-negative-positive-buttons) – Prakash Gajera Mar 23 '16 at 13:02

2 Answers2

1
(Dialog.class.cast(arg0)).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
0

use this code:

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

see this link

Community
  • 1
  • 1
Haniyeh Khaksar
  • 774
  • 4
  • 20