title: Android recyclerview not setting the items on first attempt
body: <p>In my activity, I have a <code>recyclerview</code> which displays the images in grid. The activity shows images from a collection.When the collection already contains images and I open the activity, the <code>recyclerview</code> sets all the images properly. My problem is when the I select image from gallery or camera and in <code>onActivityResult()</code> method try to set that to <code>recyclerview</code> using <strong><code>adapter.notifyDataSetChanged()</code></strong> method, the <code>recyclerview</code> is not getting updated if the collection is empty. And the same code is working fine if the collection contains images and I try to upload new image to it. Basically, I'm selecting images from gallery and then in <code>onActivityResult()</code> method I'm setting the selected images to the <code>recyclerview</code> and the images are uploaded in the background to the server.</p>
  
  <p>My Adapter code</p>
  
  <pre><code>private void setAdapter(final List&lt;AlbumImagesBean&gt; albumImages) {
  adapter = new MyRecyclerAdapter&lt;AlbumImagesBean&gt;(R.layout.album_images_grid_adapter_item) {
      @Override
      protected void setupViewHolder(MAWRecyclerViewHolder holder, final int position, final AlbumImagesBean item) {
          mawViewHolder = holder;
          ProgressBar progressBar = holder.getView(R.id.progressBar);
           ((ImageView) holder.getView(R.id.ivImage)).setImageURI(Uri.parse(item.getImage()));
            }
          };
  
          adapter.init(albumImages, false);
          recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
          recyclerView.addItemDecoration(new GridRecyclerViewDivider(5, 3));
          recyclerView.setAdapter(adapter);
    }
  </code></pre>
  
  <p><code>onActivityResult()</code> method code</p>
  
  <pre><code>
      ArrayList&lt;String&gt; images = data.getStringArrayListExtra(UIConstants.INTENT_EXTRA_IMAGES);
      if (isNotNull(images)) {
          for (int i = 0; i &lt; images.size(); i++) {
              String path = images.get(i);
              newRequests = new ArrayList&lt;&gt;();
              AddFileRequest request = new AddFileRequest();
              request.setUserId(userCache.getUserData().getUserId());
              request.setType(UIConstants.UPLOAD_FILE_TYPE_ALBUM);
              request.setTypeId(albumBean.getAlbumId());
              request.setTitle(EMPTY);
              request.setFile(path);
              AlbumImagesBean imageBean = new AlbumImagesBean(path);
              imageBean.setUploading(true);
              imageBean.setLocalImage(true);
              adapter.addItem(imageBean);
              albumImages = adapter.getData();
              newRequests.add(request);
              uploadAttachmentAPICall();
            }
            adapter.notifyDataSetChanged();
          }
  
  </code></pre>
  
  <p>I'm not able to understand what's going wrong.Thanks for any help.</p>
  
  <pre><code>public void addItem(T t) {
      createDataIfNotExits();
      data.add(t);
      notifyChanges();
  }
  
  public List&lt;T&gt; getData() {
      return data;
  }
  
  private void createDataIfNotExits() {
      if (data == null) {
          data = new ArrayList&lt;&gt;();
      }
  }
  
  public void init(List&lt;T&gt; data, boolean isPagination) {
      MAWRecyclerAdapter.isPagination = isPagination;
      if (data == null) {
          throw new NullPointerException("data can not be null");
      }
      this.data = data;
      if (isPagination) {
          this.data.add(null);
      }
      notifyChanges();
  }
  </code></pre>
  
  <p>Also I have called <code>adapter.notifyDataSetChanged( );</code> in the response of API call , but still the image is not added to recyclerview.</p>