i have a problem becouse i cant display my data from firestore becouse it wannt take my id from my xml i written this with help from a video and when he write his id it takes immediately and bu my dont
video where i take it
Main activity.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()
}
}
main 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>
CodePudding user response:
In the video, he's using KotlinX.synthetics, which is a way to access XML view components in your code. This is actually deprecated at this point as you should use View Binding instead.