【发布时间】:2019-10-18 18:21:17
【问题描述】:
//entityList 是我的 HomeScreenEntity 类型的数组列表(两个字符串数据成员)
entityList 无法在 addOnSuccessListner 之外保留其数据?为什么?
val docRef = database.collection("DepartmentImages_C").document("DepartmentImages_C")
docRef.get()
.addOnSuccessListener { document ->
if (document != null) {
Log.d(TAG, "DocumentSnapshot data: ${document.data}")
entityList.add(HomeScreenEntity(document["ComputerDepartment"].toString(),"ComputerDepartment"))
entityList.add(HomeScreenEntity(document["LawDepartment"].toString(),"LawDepartment"))
entityList.add(HomeScreenEntity(document["LiteratureDepartment"].toString(),"LiteratureDepartment"))
entityList.add(HomeScreenEntity(document["ScienceDepartment"].toString(),"ScienceDepartment"))
Toast.makeText(application.applicationContext,entityList[0].departmentName,Toast.LENGTH_SHORT).show() // this one is working fine
} else {
Log.d(TAG, "No such document")
}
}
.addOnFailureListener { exception ->
Log.d(TAG, "get failed with ", exception)
}
Toast.makeText(application.applicationContext,entityList[0].departmentName,Toast.LENGTH_SHORT).show() // this toast message is giving me index out of bound error
}
entityList 无法在 addOnSuccessListner 之外保留其数据?为什么??*/
【问题讨论】:
标签: android firebase kotlin arraylist google-cloud-firestore