How to avoid multiple button click at same time in android?

前端 未结 12 2061
太阳男子
太阳男子 2020-12-02 09:05

I\'m using two button in view. While clicking two button simultaneously it will goes to different activity at a time. How to avoid this?

I have tried like this, But

12条回答
  •  忘掉有多难
    2020-12-02 09:49

    A "Better" Practice is to use the onClickListener like this ->

    OnClickListener switchableListener = new OnClickListener(@Override
        public void onClick(View arg0) {
            arg0.setOnClickListener(null);
    
            (or) use the view directly as a final variable in case of errors
                 ex :
                         textView.setOnClickListener(null);
    
    
             // Some processing done here
    
             Completed , enable the onclicklistener arg0.setOnClickListener(switchableListener);
        });
    

    This should fix the problem and its quite a simple way of handling things

提交回复
热议问题