Duplication in Checkbox selection in RecyclerView

后端 未结 4 1899
无人共我
无人共我 2020-12-11 23:38

Below is the my code.

holder.followDiseaseCheckBox.setOnClickListener(new View.OnClickListener() {
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
          


        
4条回答
  •  悲哀的现实
    2020-12-12 00:44

    You might have missing some concepts of recylerview. Fact is that recyclerview binds/ recycles same view after every 9 items. So inorder to avoid this just make use of setItemViewCacheSize() in your activity.

    example:

    contactListAdapter = new ContactsListAdapter(ContactActivity.this, contactArrayList);
            mRecyclerView.setItemViewCacheSize(contactArrayList.size());
            mRecyclerView.setAdapter(contactListAdapter);
    

    public void setItemViewCacheSize(int size) Set the number of offscreen views to retain before adding them to the potentially shared recycled view pool. The offscreen view cache stays aware of changes in the attached adapter, allowing a LayoutManager to reuse those views unmodified without needing to return to the adapter to rebind them. Parameters: size - Number of views to cache offscreen before returning them to the general recycled view pool

提交回复
热议问题