Как вывести в консоль sumAllvalue, count за пределами addValueEventListener ?
fun allDeviceLike() {
var count : Int = 0
var sumAllvalue : Int = 0
mDeviceLikesRef.addValueEventListener(object : ValueEventListener{
override fun onCancelled(p0: DatabaseError?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onDataChange(dataSnapshot: DataSnapshot?) {
for (child : DataSnapshot in dataSnapshot?.children!!) {
var objectMap : Map<String, Any>
objectMap = child.value as Map<String, Any>;
for(entary in objectMap) {
if(entary.key.equals("value")) {
count++
sumAllvalue += entary.value.toString().toInt()
}
}
}
println(sumAllvalue) // 9 [3 + 5 + 1]
println(count) // 3 [1 + 1 + 1]
}
})
println(sumAllvalue) // 0
println(count) // 0
}