标签:android android-recyclerview countdowntimer
我有一个包含Image,Text和CountDownTimer的Product列表的RecyclerView,我将每个秒的接口CallBack调用从我的Product类更改为我的Adapter.我只需要刷新我的布局的一个TextView,但需要通知notifyItemChanged调用onBindViewHolder并刷新我项目的所有数据.仅刷新项目的一个TextView的最佳方法是什么?
public void onBindViewHolder(final ViewHolderCustom holder, final int position) {
final Product currentProduct = listProduct.get(position);
holder.productBrand.setText(currentProduct.getBrand());
holder.productName.setText(currentProduct.getName());
holder.productPrice.setText(currentProduct.getPrice());
holder.time.setText(String.valueOf(currentProduct.getTime()));
String urlImg = currentProduct.getPicture();
Log.v("adapter", "item " + position);
if (!urlImg.equals("empty")) {
imageLoader.get(urlImg, new ImageLoader.ImageListener(){...});
}
if (currentProduct.getId() == 1 && test == 0) {
test = 1;
currentProduct.Start_countDown(new Product.TimeCallBack() {
@Override
public void timeCallback(Product product) {
int index = listProduct.indexOf(product);
notifyItemChanged(index);
}
});
}
}
解决方法:
notifyItemChanged(位置);如果要重绘整个项目,这是正确的方法.如果背景有大图像,即使在缓存时,如果在同一项目上过快地调用notifyItemChanged,也会看到一些闪烁.
对于您的用例,您只需要重绘一个视图,这样您就可以直接更新它,如下所示:
public void updateTime(ViewHolderCustom holder) {
holder.time.setText(String.valueOf(currentProduct.getTime()));
holder.time.invalidate();
}
标签:android,android-recyclerview,countdowntimer 来源: https://codeday.me/bug/20190706/1399125.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。