Answer the question
In order to leave comments, you need to log in
How to get a variable from a function?
How to get data from the res1 variable outside the function so that it can be used later in the code.
fun lastCarpetId( ) {
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
val res1 = StringBuffer()
db.collection("carpets")
.orderBy("carpetid")
.limit(1)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
for (document in it.result!!) {
res1.append(document.data.getValue("carpetid")).append("")
}
}
}
}
Answer the question
In order to leave comments, you need to log in
lastCarpetId { value ->
//value получен
}
fun lastCarpetId(callback: (String) -> Unit) {
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
db.collection("carpets")
.orderBy("carpetid")
.limit(1)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
for (document in it.result!!) {
callback(document.data.getValue("carpetid"))
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question