FirebaseIndexRecyclerAdapter onDataChanged被调用,但getItemCount()总是返回0 [英] FirebaseIndexRecyclerAdapter onDataChanged is called but getItemCount() always return 0
问题描述
我使用 FirebaseIndexRecyclerAdapter
得到一个keyRef和dataRef,这对获取keyRef中所有的dataRef的子键是非常有帮助的。 / p>
数据显示正确,但如果我重写 onDataChanged
来隐藏进度条和/或显示空状态取决于itemsCount(我已经用 FirebaseRecyclerAdapter
完成的工作,并按预期工作),但
private类MYAdapter扩展了FirebaseIndexRecyclerAdapter< Item,ItemHolder> {
。
。
@Override
protected void onDataChanged(){
super.onDataChanged();
// getItemCount()== 0总是
}
。
。
$ / code>
我调查过它,原因是 FirebaseIndexRecyclerAdapter
使用 FirebaseIndexArray
来覆盖 getItemCount
并返回 mDataSnapshots .size()
但数据还没有加载 - onDataChanged
被调用,因为keyRef加载 - 事实上,我可以看到在调试中,关键是加载(正确的计数),但不幸的是,他们是私人的,所以我不能用它们来计数。
我知道我可以覆盖 onChildChanged
然后调用 getItemCount
并且得到正确的计数(我已经完成),但是仍然不知道是否没有项目,我需要显示空状态。
使用 com.firebaseui:firebase-ui:1.2.0
有什么我失踪?
注意 - 我知道我可以在数据旁边管理自己的计数(子),只需在设置适配器之前加载它,保存这个作为最后的手段。
谢谢!
,在FirebaseUI-Android github库中打开问题之后,按照@Frank van Puffelen,我从@SUPERCILEX得到了一个答案,说 onDataChanged
确实在 FirebaseIndexRecyclerAdapter
中被破坏,并且将被修复在2.0版即将推出。
I'm using FirebaseIndexRecyclerAdapter
which gets a keyRef and dataRef and is very helpful with getting all dataRef's children which their keys exists as children in keyRef.
The data is being displayed correctly but if i'm overriding onDataChanged
for hiding a progress bar and/or displaying an empty state depends on the itemsCount (Something which i've already done with FirebaseRecyclerAdapter
and works as expected) but getItemCount
always return 0(!)
private class MYAdapter extends FirebaseIndexRecyclerAdapter<Item, ItemHolder> {
.
.
@Override
protected void onDataChanged() {
super.onDataChanged();
// getItemCount() == 0 here always
}
.
.
}
I've investigate it and the reason is that FirebaseIndexRecyclerAdapter
is using FirebaseIndexArray
which is overriding getItemCount
and return mDataSnapshots.size()
but the data was not loaded yet - the onDataChanged
was called because the keyRef loaded - and indeed i can see in debug that the keys are loaded (with the correct count) but unfortunately they are private so i can't use them to get the count.
I know i can override onChildChanged
and then call getItemCount
and get the correct count (which i've done) but still i can't know if there are no items and i need to display the empty state.
Using com.firebaseui:firebase-ui:1.2.0
Is there something i'm missing?
Note - I know i can manage my own count (child) beside the data and just load it before setting the adapter but i'm saving this as a last resort.
Thanks!
So, after opening a issue in the FirebaseUI-Android github repo, as suggested by @Frank van Puffelen, i got an answer from @SUPERCILEX saying that onDataChanged
is indeed broken in FirebaseIndexRecyclerAdapter
and will be fixed in v2.0 which will be coming soon.
这篇关于FirebaseIndexRecyclerAdapter onDataChanged被调用,但getItemCount()总是返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!