By using this simple section adapter in my app to make tow sections in RecyclerView ,every thing is work greet but the problem is in the SimpleSectionedRecyclerViewAdapter.java
class
when called notifyDataSetChanged();
the code of error is :
mBaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
mValid = mBaseAdapter.getItemCount()>0;
notifyDataSetChanged(); //<------------------------the error is here
}
@Override
.
.
.
});
in my fragment I added tow type of data unfinished tasks
and finished tasks
to recyclerview
and every section has the size of their items count , the start position of second section will change depend on the unfinished tasks
size
for example I have 5 Tasks
and all of them is in the unfinished tasks
section so by click on item in the RecyclerView
the task will be finished and now i need to call notifyDataSetChanged();
so the result will be 4 items in Unfinished Tasks section
and 1 item will added to finished task section
every thing work good but the data in recyclerView
is not Changed and when I call notifyDataSetChanged();
the app crash and show error :
java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling androidx.recyclerview.widget.RecyclerView
So I comment the notifyDataSetChanged();
and the data in RecyclerView
Not changed accept when I reopen the fragment
Any Help how can I solve this ?