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

前端 未结 12 1989
太阳男子
太阳男子 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:59

    first :

    public class ClickValidate {
        public static long lastClickTime;
    
        public static boolean isValid()
        {
            long current=System.currentTimeMillis();
            long def = current - lastClickTime;
            if (def>1000)
            {
                lastClickTime = System.currentTimeMillis();
                return true;
            }
            else
                return false;
        }
    }
    

    Now just call this method everywhere in the body of onCLick method Or wherever you need:

    if (ClickValidate.isValid()){
    
       //your code
    
    }
    

提交回复
热议问题