首先創(chuàng)建工具類
public class NoFastClickUtils {
private static long lastClickTime =0;//上次點(diǎn)擊的時(shí)間
? ? private static int spaceTime =1000;//時(shí)間間隔
? ? public static boolean isFastClick() {
long currentTime = System.currentTimeMillis();//當(dāng)前系統(tǒng)時(shí)間
? ? ? ? boolean isAllowClick;//是否允許點(diǎn)擊
? ? ? ? if (currentTime -lastClickTime >spaceTime) {
isAllowClick =false;
}else {
isAllowClick =true;
}
lastClickTime = currentTime;
return isAllowClick;
}
}
在控件監(jiān)聽中調(diào)用
imageView.setOnClickListener(new View.OnClickListener() {
@Override
? ? public void onClick(View v) {
if (NoFastClickUtils.isFastClick()){
ToastUtils.ShortToast(mContext,"點(diǎn)擊間隔太短旺遮!");
}else {
listener.onImageAdClick(type,aimsId);
}
}
});