首页 > 解决方案 > 我正在尝试构建一个 Tinder 克隆,在其中我想过滤我在“刷卡”上显示的用户

问题描述

必须根据位置、首选性别等多个属性进行过滤。为此,我使用 Firebase 数据库作为我的后端。我正在使用查询字符串相应地获取数据,例如,

     fun populateItems() 
    {
    if (noUsersLayout == null) {
        progressLayout.visibility = View.VISIBLE
    }
    noUsersLayout.visibility = View.GONE
    progressLayout.visibility = View.VISIBLE
    val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)
    cardsQuery.addListenerForSingleValueEvent(object : ValueEventListener {
        override fun onCancelled(p0: DatabaseError) {

        }

        override fun onDataChange(p0: DataSnapshot) {
            p0.children.forEach { child ->
                val user = child.getValue(User::class.java)
                            var showUser = true
                            if (child.child(DATA_SWIPES_LEFT).hasChild(userId) ||
                                child.child(DATA_SWIPES_RIGHT).hasChild(userId) ||
                                child.child(DATA_MATCHES).hasChild(userId)){
                                showUser = false
                            }
                            if (showUser) {
                                rowItems.add(user!!)
                                cardsAdapter?.notifyDataSetChanged()
                            }

                progressLayout.visibility = View.GONE
                if (rowItems.isEmpty()) {
                    noUsersLayout.visibility = View.VISIBLE
                }

                    }

                }
            })

那么如何向该语句添加多个查询呢?IE

val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)随着userDatabase.orderByChild(DATA_GENDER).equalTo(preferredGender)

我试过使用.also{}.with{}但没有用。

标签: androidfirebaseandroid-fragmentskotlinfirebase-realtime-database

解决方案


推荐阅读