Android RecycleView全部item倒计时的高效实现

需要使用全局的定时器,而不是每条item均设置定时器,而且在可见视图内定时刷新UI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public void initTimer() {
mTimer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
onDownTimeTask();
}
};
mTimer.schedule(timerTask, 0, 1000);
}

private void onDownTimeTask() {
if (mBargainOrderList != null && mBargainOrderList.size() > 0) {
int firstVisiblePosition = mLayoutManager.findFirstVisibleItemPosition();
int lastVisiblePosition = mLayoutManager.findLastVisibleItemPosition();
for (int i = 0; i < mBargainOrderList.size(); i++) {
if (i >= firstVisiblePosition && i <= lastVisiblePosition) {
final BargainOrderAdapter.ViewHolder viewHolder = (BargainOrderAdapter.ViewHolder) mMyBargainOrderListRecyclerView.findViewHolderForLayoutPosition(i);
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
viewHolder.bargainCountdownView.refresh();
}
});
}
}
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :