android - 我正在尝试构建一个 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{}
但没有用。
解决方案
推荐阅读
- java - 将与 ListView 单元格关联的数据传递给项目的另一个活动 onClick()
- python - ParaView Python 脚本导致无响应的可视化工具包 - Windows 上的 Win32OpenGL
- c++ - 为什么按功能键或箭头键时 getch 返回三个值?
- c - 参数化的通用 C 宏
- python - 你如何写出“A大于B,C和D”在一个有效的事情?
- java - Java 一次填充 2 个字节的数组
- database - Symfony 3 数据库连接
- vba - VBA宏:编译错误预期语句结束
- python - Pandas - 获取具有相同行值的多列值,并输入到 1 列
- javascript - 用javaScript注入的html文本输入忽略onclick材料设计css