Get the data from the Firebase in limit to perform pull to refresh and load more functionality

前端 未结 2 1997
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 09:54

Yet now i am getting the all data from the FireBase at one time.What i want to do that getting data in LIMITS like 15 records at a tim

2条回答
  •  天涯浪人
    2020-12-01 10:31

    restructure your database, set a new child id which is incremental like 0,1,2,3... etc

    "chats": {
    "-KZLKDF": {
      "id": 0,
      "message": "Hi",
      "name":"username"
    },
    

    then make a method for query

    public void loadFromFirebase(int startValue,int endValue){
    
    mChatRef.orderByChild(id).startAt(startValue).endAt(endValue).addListenerForSingleValueEvent(this);
    }
    

    make sure you have implemented addListenerForSingleValueEvent then do adapter related task. Initially call from onCreate method:

    loadFromFirebase(0,10);
    

    NB: loading new content in the list you have to be aware with adapter.

提交回复
热议问题