I\'m adding content to my database (Firebase) which are suppose to be loaded into my recyclerview. But the new content always appear at the bottom of the re
I finally solved the issue all i needed to do was to initialize an integer variable as 0,add it along side with the object of the model class that is to be gotten from the Firebase database and finally notifying an item inserted to the adapter.The code will explain better
int position = 0;
ArrayList data = new ArrayList<>();
LinearLayoutManager lg = new LinearLayoutManager(this);
then the final code was this
valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
Places content = ds.getValue(Places.class);
data.add(position,content);
adapter = new YourAdapter(data, getApplicationContext);
recyclerview.setLayoutManager(new Line);
recyclerview.setAdapter(adapter);
adapter.notifyItemInserted(position);
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Handle error code here
}
});