以下是我的onBindViewHolder
(inside MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>
)代码的一部分
@Override
public 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
未按预期工作。当我向下滚动时,视图工作正常。但是,当我开始向上滚动,即重新访问以前的视图时,应该是的 ImageViewsVISIBLE
变为GONE
,尽管我检查了我的数据集并确认它没有被修改。尝试在视图上调用其他方法也会给出不稳定的结果(数据集中的位置和项目不匹配)。
似乎视图持有者没有绑定到 RecyclerView 内的特定位置。
如果我删除该HIDE THE VIEW
部分,代码将按预期工作。有没有办法解决这个问题并在我的情况下动态隐藏视图?
注意:我使用了一些 AsyncTasks 来更新数据集并调用notifyDataSetChanged()
,如果这是相关的。