80,493
社区成员
发帖
与我相关
我的任务
分享@Override
protected void convert(final BaseViewHolder helper, final ListBean item)if (mTimer != null) {
mTimer.cancel(); //防止new出多个导致时间跳动加速
mTimer = null;
}
mTimer = new CountDownTimer(mCloseTime - DateUtils.getCurDateStr(), 1000) {
@Override
public void onTick(long millisUntilFinished) {
helper.setText(R.id.tv_order_status, HcBaseApplication.hcString(R.string.shop_order_close_time, DateUtils.getmmss(millisUntilFinished / 1000)));
}
@Override
public void onFinish() {
helper.setText(R.id.tv_order_status, "交易关闭");
}
};
mTimer.start();
public class CountDownAdapter extends BaseQuickAdapter<Long, CountDownAdapter.CountDownHolder> {
public CountDownAdapter() {
super(R.layout.item_countdown);
}
@Override
protected void convert(CountDownHolder helper, Long item) {
if (helper.timer != null) {
helper.timer.cancel();
}
long left = item - System.currentTimeMillis();
if (left <= 0) {
helper.timer = null;
helper.setText(R.id.time, "倒计时结束");
} else {
helper.setText(R.id.time, String.format(Locale.getDefault(), "%1$ss", (left / 1000 + (left % 1000 == 0 ? 0 : 1))));
helper.timer = new CustomCountDown(left, 1000, helper.getView(R.id.time));
helper.timer.start();
}
}
private class CustomCountDown extends CountDownTimer {
private TextView time;
public CustomCountDown(long millisInFuture, long countDownInterval, TextView time) {
super(millisInFuture, countDownInterval);
this.time = time;
}
@Override
public void onTick(long left) {
time.setText(String.format(Locale.getDefault(), "%1$ss", (left / 1000 + (left % 1000 == 0 ? 0 : 1))));
}
@Override
public void onFinish() {
time.setText("倒计时结束");
}
}
public class CountDownHolder extends BaseViewHolder {
private CountDownTimer timer;
public CountDownHolder(View view) {
super(view);
}
}
}