以下是我的onBindVIEwHolder代码的一部分(在MyAdapter中扩展了RecyclerVIEw.Adapter< MyAdapter.VIEwHolder>)
@OverrIDepublic voID onBindVIEwHolder(VIEwHolder holder, int position) { // - get element from your dataset at this position StatusItem item = mDataset.get(position); //...... //Add content and timing to the textvIEw String content = item.getContent(); holder.mTextVIEwTime.setText(timing); //Set the img holder.imgVIEwIcon.setimageDrawable(item.getProfileDrawable()); //Set content image (for Instagram) holder.mImageVIEwContentPic.setimageDrawable(item.getContentDrawable()); //HIDE THE VIEW Start if(item.getContentDrawable() == null){ holder.mImageVIEwContentPic.setVisibility(VIEw.GONE); } //HIDE THE VIEW End}
HIDE THE VIEW部分未按预期工作.
当我向下滚动时,视图正常工作.但是,当我开始向上滚动,即重新访问前面的视图时,应该是VISIBLE的ImageVIEw变为GONE,尽管我检查了我的数据集并验证它没有被修改.尝试在视图上调用其他方法也会产生不稳定的结果(数据集中的位置和项目不匹配).
似乎视图持有者没有绑定到RecyclerVIEw内的特定位置.
如果我删除HIDE THE VIEW部分,代码将按预期工作.
有没有办法解决这个问题,并在我的情况下动态隐藏视图?
注意:我使用了一些AsyncTasks来更新数据集并调用notifyDataSetChanged(),如果这是相关的.
解决方法:
###This is the solution to your problem:###holder.mImageVIEwContentPic.setVisibility(VIEw.VISIBLE);if(item.getContentDrawable() == null){ holder.mImageVIEwContentPic.setVisibility(VIEw.GONE); }
总结 以上是内存溢出为你收集整理的android – RecyclerView.Adapter中的ViewHolder并不特定于位置全部内容,希望文章能够帮你解决android – RecyclerView.Adapter中的ViewHolder并不特定于位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)