Jude95 / EasyRecyclerView

ArrayAdapter,pull to refresh,auto load more,Header/Footer,EmptyView,ProgressView,ErrorView
2.03k stars 459 forks source link

OnItemClick change affects other rows in the Recyclerview #194

Closed bmbariah closed 7 years ago

bmbariah commented 7 years ago

I am using your demo app and noticed that if I change the background color of any item in the view via OnItemClick, say to color red; Some other untouched views will also be changed..

To replicate this bug simply:

  1. Add this code in your any activity
 adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                recyclerView.getRecyclerView().findViewHolderForAdapterPosition(position + adapter.getHeaderCount()).itemView.setBackgroundColor(Color.RED);
            }
        });
  1. Add a margin to item_person.xml... To allow you to see the background change.
  2. Load more data into DataProvider.java.. Try with at least 20 or 30 items

You'll notice that if you click on an item and it's background changes to RED then scroll further down, other rows will be RED even though they haven't been touched. This issue is replicated even with OnItemClick in ViewHolder.

Kindly assist...Thanks

Jude95 commented 7 years ago

Do you know why RecyclerView called 'Recycler'? You can repeat this in any RecyclerView.

I suggest you to save color state in data, and set the onclicklistener for itemview in viewholder to change data's color state, and render the view at the beginning of setData.

bmbariah commented 7 years ago

Sorry ! Fixed this issue weeks ago but forgot to close it here.