简体   繁体   中英

How to Disable Button after first Click in android

I am using this code but its not working i am still able to click more than 2 times.

accept.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        accept.setEnabled(false);
                        if (dialog1 != null && dialog1.isShowing()) {
                            dialog1.dismiss();
                        }
                        handler.removeCallbacks(runnable);
                    }
                });

its not showing any error but not working as desired.

boolean run = true;
accept.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        if(run) {
            run = false;
            //your code
        }
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM