I used ListView to dynamic add item,but there is a problem about not Smooth add.
there are textView and button in my listActivity,Iwant to Press button ,then
Yes!!, the method notifyDataSetChanged() applied in the ArrayAdapter before you fulling him, was the solution for me. Reading from Firebase.
Objects
private DatabaseReference myRef;
ArrayList lista;
ArrayAdapter adapter;
OnCreate
FirebaseDatabase database = FirebaseDatabase.getInstance();
myRef = database.getReference("chat");
//GETTIN MY DATA TO SHOW IN CHAT
lista = new ArrayList();
OnResume
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnappy : dataSnapshot.getChildren()){
for (DataSnapshot rePostSnappy : postSnappy.getChildren()){
// Defined Array values to show in ListView
lista.add(new String(rePostSnappy.getValue().toString()));
adapter.notifyDataSetChanged();//Notyfing adapter that will goes to change
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, lista);
ListView listVista = (ListView) findViewById(R.id.list);
listVista.setAdapter(adapter);