Is there a way to filter data with Firebase UI RecyclerView?

大兔子大兔子 提交于 2020-12-27 06:33:47

问题


I'm using the Firebase UI FirestorePagingAdapter, i have a colletion of posts and i want to filter the post that are not from the current user and order them by timestamp

I tried doing this but i get inequality error:

override fun getPostFromLocation(viewLifecycleOwner:LifecycleOwner, location:String) :FirestorePagingOptions<Post>{
    val query = firestore.collection(POST_COLLECTION)
        .orderBy("timestamp", Query.Direction.DESCENDING)
        .whereNotEqualTo("uid",auth.currentUser?.uid)
    return FirestorePagingOptions.Builder<Post>()
        .setLifecycleOwner(viewLifecycleOwner)
        .setQuery(query, pagingConfig, Post::class.java)
        .build()
}

Is there a way i can filter the results?


回答1:


If you want to use Firebase UI to manage the RecyclerView, you will have to filter the results with another condition on the query.

If you can't make the query return exactly what you want, you will not be able to use Firebase UI. Instead, you will have to manually perform the query, write code to filter the results, and apply those to a RecyclerView with your own adapter.



来源:https://stackoverflow.com/questions/65111509/is-there-a-way-to-filter-data-with-firebase-ui-recyclerview

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