Firebase android pagination

后端 未结 10 1502
天命终不由人
天命终不由人 2020-11-28 09:14

I\'m building an app which will show videos stored on firebase. The list of videos needs to be paginated fetching most recent 20 videos at a time.

Here is

10条回答
  •  遥遥无期
    2020-11-28 09:31

    You want to be using the limitToFirst/limitToLast methods to retrieve a limited number of results.

    videosQuery.orderByKey().limitToFirst(20)
    

    https://www.firebase.com/docs/web/api/query/limittofirst.html

    You should really consider changing the naming convention of your videos to include leading 0s (i.e. video01, video02... video10, video11) because the above code will display them exactly as you have them above (which I assume is out of order?)

    Alternatively, if you're adding the videos via Java, you could just let firebase create the uniqueids via push(). The uniqueid are generated in a way that they'll sort chronilogically, which sounds like it'll suit your need to grab the most recent(ly added?) videos.

    https://www.firebase.com/docs/web/api/firebase/push.html

提交回复
热议问题