这是我的代码
当我上下滚动时,图像也添加到其他位置,即使在那些位置,图像路径也不存在.假设图像路径位于1,2和3位置,但它也显示图像位于4,10,15位置等
public class Contact_Adapter_RecyeckVIEw extendsRecyclerVIEw.Adapter<Contact_Adapter_RecyeckVIEw.VIEwHolder> {private ArrayList<ContactBean> arrayList;private Context context;public Contact_Adapter_RecyeckVIEw(Context context, ArrayList<ContactBean> arraylistimages) { this.arrayList = arraylistimages; this.context = context;}// Create new vIEws (invoked by the layout manager)@OverrIDepublic Contact_Adapter_RecyeckVIEw.VIEwHolder onCreateVIEwHolder( VIEwGroup parent, int vIEwType) { // create a new vIEw VIEw itemLayoutVIEw = LayoutInflater.from(parent.getContext()).inflate( R.layout.contact_adapter_recyclevIEw, null); // create VIEwHolder VIEwHolder vIEwHolder = new VIEwHolder(itemLayoutVIEw); return vIEwHolder;}// Replace the contents of a vIEw (invoked by the layout manager)@OverrIDepublic voID onBindVIEwHolder(VIEwHolder vIEwHolder, int pos) { String image = arrayList.get(pos).getimage(); file imgfile = new file(image); if(imgfile.exists()) { vIEwHolder.ivProfile.setimageURI(Uri.fromfile(imgfile)); } //vIEwHolder.ivProfile.setimageBitmap(BitmapFactory.decodefile(arrayList.get(pos).getimage())); //vIEwHolder.ivProfile.setVisibility(VIEw.VISIBLE); // inner class to hold a reference to each item of RecyclerVIEwpublic static class VIEwHolder extends RecyclerVIEw.VIEwHolder { public ImageVIEw ivProfile; public VIEw vIEw; public CardVIEw cardvIEw; public VIEwHolder(VIEw itemLayoutVIEw) { super(itemLayoutVIEw); ivProfile = (ImageVIEw) itemLayoutVIEw .findVIEwByID(R.ID.iv_user_profile); }}// Return the size of your itemsData (invoked by the layout manager)@OverrIDepublic int getItemCount() { return arrayList.size();}}
我也看到过此链接,但仍然存在相同问题scroll when change找不到
解决方法:
您需要在else bloc中重置默认图像,否则回收机制将重新使用旧图像.
@OverrIDepublic voID onBindVIEwHolder(VIEwHolder vIEwHolder, int pos) { String image = arrayList.get(pos).getimage(); file imgfile = new file(image); if(imgfile.exists()){ vIEwHolder.ivProfile.setimageURI(Uri.fromfile(imgfile)); } else { // here you set your default image, or you can just hIDe "vIEwHolder.ivProfile" }}
总结 以上是内存溢出为你收集整理的android-当我在Recyclerview中向下滚动时,回收无法正常工作全部内容,希望文章能够帮你解决android-当我在Recyclerview中向下滚动时,回收无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)