我从Firebase数据中删除数据时遇到问题。我有向数据库添加名称和姓氏的应用程序,以及将其删除的按钮。
我如何实现deleteUser功能? 用户单击“按钮”,然后删除带有此数据的行。
val database = FirebaseDatabase.getInstance()
myRef = database.getReference("Users")
recycler_view.layoutManager = GridLayoutManager(applicationContext, 1)
submitdataBTN.setOnClickListener {
val name = nameInput.text.toString()
val surname = surnameInput.text.toString()
val firebaseIntent = DatabaseRow(name, surname)
myRef.child("${Date().time}").setValue(firebaseIntent)
}
在行上添加用户
myRef.addValueEventListener(object : ValueEventListener {
override fun onCancelled(databaseError: DatabaseError) {
TODO("Not yet implemented")
}
override fun onDataChange(databaseSnapshot: DataSnapshot) {
listofItems = ArrayList()
for (i in databaseSnapshot.children) {
val newRow = i.getValue(DatabaseRow::class.java)
listofItems.add(newRow!!)
}
setupAdapter(listofItems)
}
})
This is my UI and when user click delete then remove data from row
如何实现删除数据功能?