i have been working to retrive data from firebase realtime database to listview in my application but when it comes to listview i wanted to show the last retrived data in top of the listview.this is my code for retriving data and setting to listview,using this code the data is retrived to bottom of listview
list = new ArrayList<>();
adapter = new ArrayAdapter<String>(this, R.layout.notifi, R.id.notifi, list);
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
notif = ds.getValue(notificationclass.class);
list.add(notif.getNotification());
}
listView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
};
databaseReference.addValueEventListener(postListener);
}
}