FirebaseIndexRecyclerAdapter onDataChanged is called but getItemCount() always return 0

别等时光非礼了梦想. 提交于 2020-01-13 19:49:21

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/44091290/firebaseindexrecycleradapter-ondatachanged-is-called-but-getitemcount-always-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!