问题
I am building an app that i would like to fetch data from Firestore and display it in recyclerview as the user scrolls.
I am using FirestorePagingAdapter as described here: https://github.com/firebase/FirebaseUI-Android/tree/master/firestore#using-the-firestorepagingadapter.
This adapter does not listen for realtime changes in the database, how do I manually force a refresh using swipeRefreshLayout?
回答1:
The FirestorePagingAdapter
will load the data fresh from the database whenever it shows a new page. But beyond that it has no built-in way to refresh the data.
If you want to load fresh data for the current page, you will have to create a new FirestorePagingAdapter
instance in your swipe handler. The code will be the same as how you initially instantiate that adapter. Don't forget to call stopListening()
来源:https://stackoverflow.com/questions/53360442/how-to-refresh-data-in-a-firestore-paging-adapter-using-swipe-refresh-layout