class MainActivity : AppCompatActivity() {
lateinit var recyclerView: RecyclerView
lateinit var list: ArrayList<ItemData>
lateinit var adapter: RecyclerAdapter
lateinit var firebaseDatabase: FirebaseDatabase
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recyclerView = findViewById(R.id.recyclerview)
var layoutManager = LinearLayoutManager(this)
recyclerView.layoutManager=layoutManager
recyclerView.setHasFixedSize(true)
firebaseDatabase = FirebaseDatabase.getInstance()
list = ArrayList()
getDataFromFirebase()
}
private fun getDataFromFirebase() {
firebaseDatabase.reference.child("images").addListenerForSingleValueEvent(object :ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
for (dataSnapshot in snapshot.children){
var data:ItemData?= dataSnapshot.getValue(ItemData::class.java)
list.add(data!!)
}
adapter=RecyclerAdapter(list,this@MainActivity)
recyclerView.adapter=adapter
adapter.notifyDataSetChanged()
}
override fun onCancelled(error: DatabaseError) {
Toast.makeText(this@MainActivity,"error", Toast.LENGTH_LONG).show()
}
})
}
}
adapter.notifyDataSetChanged() - não sei como deveria implementar mas a aplicação não esta capturando a mudança no firebase em tempo real
Eu tenho que recarregar a aplicação