Closed marc97 closed 7 years ago
I guess RecyclerView.AdapterDataObserver.onItemRangeInserted()
or RecyclerView.AdapterDataObserver.onItemRangeRemoved()
is called instead of RecyclerView.AdapterDataObserver.onChanged()
.
Could you check those methods as well?
Recent RecyclerViewRealmAdapter
calles RecyclerView.Adapter.notifyItemRangeInserted()
or RecyclerView.Adapter.notifyItemRangeRemoved()
instead of RecyclerView.Adapter.notifyDataSetChanged()
and notifyItemRangeInserted()
and notifyItemRangeRemoved()
does not trigger onChanged()
.
I have the same problem. I checked, instead of RecyclerView.AdapterDataObserver.onChanged()
, called RecyclerView.AdapterDataObserver.onItemRangeInserted()
or RecyclerView.AdapterDataObserver.onItemRangeRemoved()
.
@ni032mas That's the intended behavior. Why is that the problem?
@zaki50 I've checked the methods RecyclerView.AdapterDataObserver.onItemRangeInserted(
and RecyclerView.AdapterDataObserver.onItemRangeRemoved()
and both works well. This issue can be closed.
I had a problem, now it's not there )
@marc97 It's good to hear that your problem is resolved, I will close this issue.
That's the intended behavior. Why is that the problem?
Why is it intended behaviour? Surely the onChanged callback should be called whenever the data changes?
@rubenwardy To achieve correct animation on RecyclerView, more fine-grained callback than onChanged ()
should be called.
class foo: Fragment{
private val documentRecyclerView get() = dataBinding.documentRecyclerView
private fun manipulateRecyclerViewScroll(){
lifecycleScope.launchWhenResumed {
documentRecyclerView.doOnPreDraw {
documentRecyclerView.adapter!!.registerAdapterDataObserver(object :
RecyclerView.AdapterDataObserver() {
override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
super.onItemRangeChanged(positionStart, itemCount)
documentRecyclerView.scrollToPosition(0)
}
})
}
}
}
}
I have a
RecyclerViewRealmAdapter
registering aRecyclerView.AdapterDataObserver
, butonChanged()
is never fired when an item is inserted/removed in realm. I've tested it using the defaultRecyclerView.Adapter
and works perfectly.