Live codes image is here 我想读取用户在实时数据库中发布的数据。经过反复试验,我需要您的帮助来消除这些错误。
home.setOnClickListener({
val database = FirebaseDatabase.getInstance()
val child_myRef = database.getReference("users")
child_myRef.addValueEventListener(object : ValueEventListener(){
override fun onDataChange(p0: DataSnapshot?){
val list = mutableListOf<String>()
val it : Iterable<DataSnapshot> = p0!!.children
it.forEach{
val itr=it.children
var msg=" "
itr.forEach({
msg=msg+"\n" + it.value
})
list.add(msg)
}
val myadapter = ArrayAdapter<String>(this@HomeActivity, android.R.layout.simple_list_item_single_choice,list)
Lview.adapter = myadapter
}
override fun onCancelled(p0: DatabaseError?) {
}
})
})