title: Recyclerview Not showing firstTime item
body: <p>I have Recycler view in app I use recycler view in navigation drawer means fragment
  when reyclerview is empty and when I add item in recycler view that not show but after I refresh fragment and after I add item then is showing immediately but not show first time why. I am stuck.</p>
  
  <p>here is my code-:</p>
  
  <pre><code>     @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
          inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          v = inflater.inflate(R.layout.activity_consultant_note_fragment, container, false);
          mSp = getActivity().getSharedPreferences(Constant.PREF, Context.MODE_PRIVATE);
          consulatantnoterecyclerView = v.findViewById(R.id.consulatantnote_display_recycler);
          swipeRefreshLayout = v.findViewById(R.id.swipeContainer);
  
          nodatafound = v.findViewById(R.id.nodatafound);
          // GetConsulatantNote();
          RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity());
          consulatantnoterecyclerView.setLayoutManager(manager);
          consulatantnoterecyclerView.setItemAnimator(new DefaultItemAnimator());
  
         return v;
      }
  
       void GetConsulatantNote() {
          dialog = new ProgressDialog(getActivity());
          dialog.show();
          if (!Utils.isInternetAvailable(getActivity(), true))
              return;
  
          final ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
  
          ConsultantNote request = new ConsultantNote();
          request.setActionBy(Integer.valueOf(mSp.getString(Constant.ActionBy, "")));
          request.setInPatientID(Integer.valueOf(mSp.getString(Constant.InPatientID, "")));
          request.setToken(mSp.getString(Constant.TOKEN, ""));
          request.setCreatedBy(Integer.valueOf(mSp.getString(Constant.MasterUserID, "")));
          request.setIsActive(1);
  
  
          ServiceRequest serviceRequest = new ServiceRequest();
          serviceRequest.setOppID(**);
          serviceRequest.setParameters(request);
  
          Call&lt;ConsultantNoteResponse&gt; consultantNoteResponseCall = apiInterface.SaveConsulatantNote(serviceRequest);
          consultantNoteResponseCall.enqueue(new Callback&lt;ConsultantNoteResponse&gt;() {
              @Override
              public void onResponse(Call&lt;ConsultantNoteResponse&gt; call, Response&lt;ConsultantNoteResponse&gt; response) {
  
                  if (response.body().getSuccess() == true &amp;&amp; response.body().getValidated() == false) {
                      if (!response.body().getValidationErrors().isEmpty()) {
                          Nodatafound = true;
                          List&lt;ValidationError&gt; validationErrors = response.body().getValidationErrors();
                          for (int i = 0; i &lt; validationErrors.size(); i++) {
                              ValidationError error = new ValidationError();
                              error.setErrorMessage(validationErrors.get(i).getErrorMessage());
                              Log.d("error", "" + validationErrors.get(i).getErrorMessage());
                          }
                          // Toast.makeText(DoctorCollection.this, "Records not found for opd", Toast.LENGTH_SHORT).show();
                      }
                      dialog.dismiss();
                  }
                  if (response.body().getSuccess() == true &amp;&amp; response.body().getValidated() == true) {
                      //data
                      consultantNotes = new ArrayList&lt;&gt;();
                      consultantNotes.clear();
                      List&lt;ConsultantNote&gt; notes = response.body().getConsultantNotes();
                      consulatantnoterecyclerView.setVisibility(View.VISIBLE);
                      nodatafound.setVisibility(View.GONE);
                      for (int i = 0; i &lt; notes.size(); i++) {
  
                          ConsultantNote note = new ConsultantNote();
  
                          note.setCreatedByUserFullName(notes.get(i).getCreatedByUserFullName());
                          note.setConsultantNotesDateTime(notes.get(i).getConsultantNotesDateTime());
                          note.setPatientProgress(notes.get(i).getPatientProgress());
                          note.setCreatedBy(notes.get(i).getCreatedBy());
                          note.setInPatientConsultantNoteID(notes.get(i).getInPatientConsultantNoteID());
                          note.setProblemsAndInterventions(notes.get(i).getProblemsAndInterventions());
  
                          consultantNotes.add(note);
                      }
  
  
                      //consulatantnoterecyclerView.setAdapter(consultantNoteAdpater);
  
                      setAdapterData(consultantNotes);
                      onItemDelete();
                      if (dialog.isShowing()) {
                          dialog.dismiss();
                      }
                  }
                  if (Nodatafound) {
                      consulatantnoterecyclerView.setVisibility(View.GONE);
                      nodatafound.setVisibility(View.VISIBLE);
                  }
  
              }
  
              @Override
              public void onFailure(Call&lt;ConsultantNoteResponse&gt; call, Throwable t) {
  
              }
          });
  
          dialog.dismiss();
      }
  
  
    void onItemDelete() {
  
      final ConsultantNoteAdpater noteAdpater = new ConsultantNoteAdpater(context, consultantNotes);
      consulatantnoterecyclerView.setAdapter(noteAdpater);
  
      noteAdpater.setOnItemDeleteClickListener(new ConsultantNoteAdpater.OnItemClickDeleteListener() {
          @Override
          public void onItemClick(final int position, final Integer NoteId) {
              final AlertDialog.Builder innermsg = new AlertDialog.Builder(context);
              innermsg.setMessage("Are you sure you want to delete this consultant note ?");
              innermsg.setCancelable(false);
              innermsg.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
  
                      consultantNotes.remove(position);
                      noteAdpater.notifyItemRemoved(position);
                      noteAdpater.notifyItemRangeChanged(position, consultantNotes.size());
                      DeleteConsulatantNote(NoteId);
                      noteAdpater.notifyDataSetChanged();
                      GetConsulatantNote();
                  }
              });
              innermsg.setNegativeButton("cancle", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                  }
              });
              innermsg.show();
          }
  
  
      });
  
  }
  
  private void setAdapterData(List&lt;ConsultantNote&gt; data) {
      if (data != null) {
          ArrayList&lt;ConsultantNote&gt; notes = new ArrayList&lt;&gt;();
          notes.clear();
          notes.addAll(consultantNotes);
  
          adapter = new ConsultantNoteAdpater(getActivity(), notes);
          adapter.notifyItemRangeChanged(0, consultantNotes.size());
          // adapter.notifyDataSetChanged();
          consulatantnoterecyclerView.setAdapter(adapter);
  
  
      }
  }
  </code></pre>
  
  <p>Here is my adapter code of recyclerview-:</p>
  
  <pre><code>public class ConsultantNoteAdpater extends RecyclerView.Adapter&lt;ConsultantNoteAdpater.holder&gt; {
  
  
  LayoutInflater layoutInflater;
  Context context;
  List&lt;ConsultantNote&gt; consultantNotes;
  private SharedPreferences mSp;
  public OnItemClickDeleteListener onItemClickDeleteListener;
  
  public ConsultantNoteAdpater(Context c, List&lt;ConsultantNote&gt; notes) {
      context = c;
      consultantNotes = notes;
      notifyDataSetChanged();
  }
  
  @NonNull
  @Override
  public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View v = layoutInflater.inflate(R.layout.activity_consultant_note_adpater, parent, false);
      mSp = context.getSharedPreferences(Constant.PREF, Context.MODE_PRIVATE);
      return new holder(v);
  }
  
  public interface OnItemClickDeleteListener {
      void onItemClick(int position, Integer NoteId);
  }
  
  public void setOnItemDeleteClickListener(OnItemClickDeleteListener onItemClickDeleteListener) {
      this.onItemClickDeleteListener = onItemClickDeleteListener;
  }
  
  @Override
  public void onBindViewHolder(@NonNull holder holder, final int position) {
  
      final ConsultantNote note = consultantNotes.get(position);
  
  
      holder.createdby.setText(Html.fromHtml(createdby + "" + note.getCreatedByUserFullName()));
  
  
      holder.delete.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (onItemClickDeleteListener != null) {
                  //get pateint consulatant note id
                  onItemClickDeleteListener.onItemClick(position, note.getInPatientConsultantNoteID());
              }
          }
      });
  
  }
  
  
  @Override
  public int getItemCount() {
      return consultantNotes.size();
  }
  
  
  
  class holder extends RecyclerView.ViewHolder {
  
      TextView date, createdby;
      ImageView delete;
  
      public holder(View itemView) {
          super(itemView);
  
          date = itemView.findViewById(R.id.consulatant_datetime);
          createdby = itemView.findViewById(R.id.consulatant_createdby);
          delete = itemView.findViewById(R.id.deleteconsultant);
      }
    }
  }
  </code></pre>
  
  <p>I am using retrofit to get data from api so if any one can help!!</p>
  
  <p>Thanks in advance!!!</p>