防止快速点击多次调节音量按钮多次调用网络接口
程序员文章站
2024-01-26 22:02:52
...
private Runnable reqeustSetVoice;
public void setDeviceVoice(final int count, BindBean bean, ImageButton deviceVoice) {
if (reqeustSetVoice == null) {
reqeustSetVoice = new Runnable() {
@Override
public void run() {
HttpManager.setDeviceVoice(bean.getMac(), count, new OnResultListener<NoDataResult>() {
@Override
public void onSuccess(NoDataResult result) {
if (result.result == 1) {
} else {
setVoiceButton(bean.getDevVoice(), deviceVoice);
onError(-1, result.message);
}
}
@Override
public void onError(int code, String message) {
Common.AlertDialog(context, message);
}
});
}
};
}
handler.removeCallbacks(reqeustSetVoice);//之前所有的请求都remove
handler.postDelayed(reqeustSetVoice, 1500);//在1.5s以内最后一次的请求才会发送出去