just for readers in future here is the required code in Kotlin:
val products = arrayListOf<Product>()
val ref = FirebaseDatabase.getInstance().getReference("products")
ref.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (productSnapshot in dataSnapshot.children) {
val product = productSnapshot.getValue(Product::class.java)
products.add(product!!)
}
System.out.println(products)
}
override fun onCancelled(databaseError: DatabaseError) {
throw databaseError.toException()
}
})
}
and you have to initialize variables in Product class like this :
data class Product(
val title:String = "",
val photo:String = "",
val description:String = "",
val price:Double = -1.0
)
if you leave it without initializing you will get class does not define a no-argument constructor
error