title: Why is my FirestoreRecyclerView not automatically showing the latest items after I login to my application?
body: <p>I have a problem with my FirestoreRecyclerView where it will not automatically show the latest items added when I login to the application. I have to manually scroll up the recyclerview, then the newly added items will be shown.</p>
  <p>Brief description of my app: My application will record a log every minute.FirestoreRecyclerView should show the latest logs at the top of the recyclerview every minute.</p>
  <p>My problem is, when I logged in at 3.53pm, the previous logs which I logged in at 3.16pm are shown instead.</p>
  <p><a href="https://i.stack.imgur.com/ggcLO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ggcLO.png" alt="enter image description here" /></a></p>
  <p>However, if I scroll up, I will see the latest 3.53pm log:</p>
  <p><a href="https://i.stack.imgur.com/rqENA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqENA.png" alt="enter image description here" /></a></p>
  <p>I am not sure why this is happening. Is there a way to show the latest log without having to scroll up? Or is there a way to clear the FirestoreRecyclerView everytime I log in?</p>
  <p>Logs Fragment Class:</p>
  <pre><code>public class UserLogsFragment extends Fragment implements UserLogsAdapter.OnListItemClick{
  
  private RecyclerView mFirestoreList;
  private FirebaseFirestore firebaseFirestore;
  private UserLogsAdapter adapter;
  private FirestoreRecyclerOptions&lt;UserLogsModel&gt; options;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.fragment_user_logs2, container, false);
  
  
      firebaseFirestore = FirebaseFirestore.getInstance();
  
  
      // Query from firebase
      Query query = firebaseFirestore.collection(&quot;UOW_log&quot;) // TODO: filter by organisation ID
              .orderBy(&quot;date&quot;, Query.Direction.DESCENDING);
  
  
      // Recycler options
      options = new FirestoreRecyclerOptions.Builder&lt;UserLogsModel&gt;()
              .setLifecycleOwner(this)
              .setQuery(query, new SnapshotParser&lt;UserLogsModel&gt;() {
                  @NonNull
                  @Override
                  public UserLogsModel parseSnapshot(@NonNull DocumentSnapshot snapshot) {
                      UserLogsModel userLogsModel = snapshot.toObject(UserLogsModel.class);
                      String docId = snapshot.getId();
                      userLogsModel.setDocument_id(docId);
                      return userLogsModel;
                  }
              })
              .build();
  
      // Create recycler adapter
      adapter = new UserLogsAdapter(options, this);
      mFirestoreList = view.findViewById(R.id.firestore_list2);
      mFirestoreList.setHasFixedSize(true);
      mFirestoreList.setLayoutManager(new LinearLayoutManager(getContext(),
              LinearLayoutManager.VERTICAL, false));
      mFirestoreList.setAdapter(adapter);
  
      return view;
  }
  
  @Override
  public void onItemClick(UserLogsModel snapshot, int position) {
      Log.d(&quot;ITEM_CLICK&quot;, &quot;Clicked the item: &quot; + position + &quot; and the ID is: &quot; + snapshot.getDocument_id());
      //startActivity(new Intent(getActivity(), LogsDetailActivity.class));
  
  
  
      Fragment fragment = UserLogDetailsFragment.newInstance(snapshot.getDocument_id());
      FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
  
  
  
      //transaction.hide(getActivity().getSupportFragmentManager().findFragmentByTag(&quot;user_logs_fragment&quot;));
      transaction.replace(R.id.container, fragment, &quot;user_log_details_fragment&quot;);
      //transaction.add(R.id.container, fragment);
      transaction.addToBackStack(null);
      transaction.commit();
  
  
  
      /*
      transaction.replace(android.R.id.content, fragment);
      transaction.addToBackStack(null);//add the transaction to the back stack so the user can navigate back
      // Commit the transaction
      transaction.commit();
      */
  
  
  
  }
  
  @Override
  public void onStart() {
      super.onStart();
  
      adapter.startListening();
  }
  
  @Override
  public void onStop() {
      super.onStop();
      adapter.stopListening();
  }
  }
  </code></pre>
  <p>Adapter class:</p>
  <pre><code>public class UserLogsAdapter extends FirestoreRecyclerAdapter&lt;UserLogsModel, UserLogsAdapter.UserLogsViewHolder&gt; {
  
  private OnListItemClick onListItemClick;
  
  public UserLogsAdapter(@NonNull FirestoreRecyclerOptions&lt;UserLogsModel&gt; options, OnListItemClick onListItemClick) {
      super(options);
  
      this.onListItemClick = onListItemClick;
  }
  
  @Override
  protected void onBindViewHolder(@NonNull UserLogsViewHolder holder, int position, @NonNull UserLogsModel model) {
  
      if(position != RecyclerView.NO_POSITION){
          // Do your binding here
          holder.doc_id.setText(model.getDocument_id());
  
      }
  
      //holder.doc_id.setText(model.getDocument_id());
      Log.d(&quot;POSITION&quot;,&quot;Position: &quot; + position);
  
  
  
  
  
  }
  
  @NonNull
  @Override
  public UserLogsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_logs_list_item_single2, parent, false);
      return new UserLogsViewHolder(view);
  }
  
  // Viewholder class for user logs
  protected class UserLogsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
      private TextView doc_id;
  
      public UserLogsViewHolder(@NonNull View itemView) {
          super(itemView);
  
          doc_id = itemView.findViewById(R.id.userLogs_recyView_docId2);
  
  
          itemView.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View view) {
          onListItemClick.onItemClick(getItem(getAdapterPosition()), getAdapterPosition());
      }
  }
  
  public interface OnListItemClick{
      void onItemClick(UserLogsModel snapshot, int position);
  }
  
  
  }
  </code></pre>