标签(空格分隔): Android
在RecycleView中显示倒计时听起来很简单,其实实现起来却不是很容易。首先设置Handler来更新界面想想也复杂,而且是在RecycleView中,用什么notifyItemChanged()或者notifyDataSetChanged()也是不行的,画面会闪烁。一种高效可行的办法是获取在界面显示的item然后刷新他们。
@Background //开启线程执行
void timeEnd() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (auctions.size()>0) {
int firstVisible = manager.findFirstVisibleItemPosition();
int lastVisible = manager.findLastVisibleItemPosition();
for (int i = 0; i < auctions.size(); i++) {
if (i >= firstVisible && i <= lastVisible) {
if (rcly_Session.findViewHolderForPosition(i).getItemViewType() != 0) {
final SessionAdapter.SessionHolder holder = (SessionAdapter.SessionHolder) rcly_Session.findViewHolderForPosition(i);
runOnUiThread(new Runnable() {
@Override
public void run() {
//textView.setText(time);
}
});
}
}
}
}
}
}