Im have a Collection called: Players Inside there each document has a value of posx and posy
i want to create an Array with Arrays for each document Like: [[posx1,posy1][[posx,posy2]...]
if i put a print inside the .addOnSuccesListener it works and prints the list but when im outside there and i try to print the list it returns empty
What i am doing wrong? Thanks
val myDB = FirebaseFirestore.getInstance()
var posiciones = ArrayList<Array<String>>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
myDB.collection("players")
.get()
.addOnSuccessListener { result ->
for (document in result) {
posiciones.add(
arrayOf(
document.get("posx").toString(),
document.get("posy").toString()
)
)
}
}
.addOnFailureListener { exception ->
Log.d(ContentValues.TAG, "Error getting documents: ", exception)
}
//i get []
println("Testing: "+ posiciones)