我有一個問題,因為我無法從firestore顯示我的資料,因為它不想從我的xml中獲取我的id 我在視頻的幫助下寫了
這個
主要活動.kt
private fun retrivePerson() = CoroutineScope(Dispatchers.IO).launch {
try {
val querySnapshot = personCollectionName.get().await()
val sb = StringBuilder()
for (document in querySnapshot.documents) {
val users = document.toObject<users>()
sb.append("$users\n")
}
withContext(Dispatchers.Main) {
uzytkownik.text = sb.toString()
/* val imie = findViewById<TextView>(R.id.uzytkownik).apply {
text = "Witaj, " sb.toString()*/
}
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
Toast.makeText(this@MainActivity, e.message, Toast.LENGTH_LONG).show()
}
}
主xml
<ScrollView
android:id="@ id/scrollView2"
android:layout_width="245dp"
android:layout_height="66dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@ id/uzytkownik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Witaj,"
android:textColor="@android:color/black"
android:textSize="18sp" />
</ScrollView>
錯誤 ID 用戶
uj5u.com熱心網友回復:
在視頻中,他使用了 KotlinX.synthetics,這是一種在您的代碼中訪問 XML 視圖組件的方法。這實際上已被棄用,因為您應該改用View Binding。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/463009.html
