Issues maving data around function


#1

Hello, I want to mave data from an inner function to the main function and i dont know how

fun getData():ArrayList {
val posts= ArrayList()
val ref= FirebaseDatabase.getInstance().getReference(“post”)
ref.addListenerForSingleValueEvent(object : ValueEventListener {
override public fun onDataChange(snapshot: DataSnapshot?){
val ps:ArrayList = ArrayList()
val children = snapshot!!.children
children.forEach {
val post=it.getValue(Post::class.java)
posts.add(post!!)
}
posts.forEach {
Log.v(“postsDre”,it.content)
}
}

        override public fun onCancelled(p0: DatabaseError?) {
            Log.v("dfb","An error dbfirebase")
        }
    })

    return posts
}

Its getting the data from the database but the function returns nothing