当前位置:  开发笔记 > 编程语言 > 正文

避免片段列表数据在recyclerView上重复

如何解决《避免片段列表数据在recyclerView上重复》经验,为你挑选了1个好方法。



1> Mayur Raval..:

试试这个

View view; // declare this globally

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if(view == null){ // initialize if view is null
     view = inflater.inflate(R.layout.vaccine_fragment_, container, false);

    recyclerVaccine = (RecyclerView) view.findViewById(R.id.recyclerVaccine);
    recyclerVaccine.setLayoutManager(new LinearLayoutManager(getActivity()));

    vaccineList.clear();// i use it to slove the problem.--------------
    testData();
    vaccineAdapter = new VaccineAdapter(getActivity(), vaccineList);
    recyclerVaccine.setAdapter(vaccineAdapter);
    vaccineAdapter.notifyDataSetChanged();
    }
    return view;
}

推荐阅读
sx-March23
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有