title: How to force RecyclerView.Adapter to call the onBindViewHolder() on all elements
body: <p>I have a <code>VerticalGridView</code> that is using a <code>RecyclerView.Adapter</code> to populate the elements. I have discovered that the <code>onBindViewHolder()</code> method does not get called if the potential element is off of the viewport. Unfortunately, this is causing a <code>NullPointerException</code> from a different method because I am catching a <code>TextView</code> reference in the <code>onBindViewHolder()</code> method and passing it to an outside variable for later manipulation.</p>
  
  <pre><code>@Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      final ViewHolder viewHolder = (ViewHolder) holder;
      viewHolder.txtCategoryName.setText(categories.get(position).getStrCategory());
      categories.get(position).setTxtViewReference(viewHolder.txtCategoryDefectTotal);
      viewHolder.categoryBoxRoot.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              for(CategoryListItem catItem : categories){
                  if(catItem.getStrCategory().equals(viewHolder.txtCategoryName.getText())){
                      int index = Defects.getInstance().getCategories().indexOf(catItem) + 1;
                      MainInterface.grids.get(index).bringToFront();
                      MainInterface.grids.get(index).setVisibility(View.VISIBLE);
                      for(VerticalGridView grid : MainInterface.grids){
                          int gridIndex = MainInterface.grids.indexOf(grid);
                          if(gridIndex != index){
                              grid.setVisibility(View.INVISIBLE);
                          }
                      }
                      break;
                  }
              }
  
          }
      });
  </code></pre>
  
  <p>From what I understand, the reference to the <code>TextView</code> gets created when the <code>Viewholder</code> object is instantiated.</p>
  
  <pre><code>public class ViewHolder extends RecyclerView.ViewHolder {
  
      public TextView txtCategoryName;
      public TextView txtCategoryDefectTotal;
      public View categoryBoxRoot;
  
      public ViewHolder(View itemView) {
          super(itemView);
          txtCategoryName = (TextView) itemView.findViewById(R.id.textViewCategoryName);
          txtCategoryDefectTotal = (TextView) itemView.findViewById(R.id.textViewCategoryTotalDefects);
          categoryBoxRoot = itemView.findViewById(R.id.root_category_box);
      }
  }
  </code></pre>
  
  <p>Is there a way to force <code>onBindViewHolder()</code> to be called on all elements at least one time when the <code>Adapter</code> is instantiated?</p>
  
  <p>I attempted the suggestions <a href="https://stackoverflow.com/questions/32913578/recyclerview-does-not-call-the-onbindviewholder-when-scroll-in-the-view">here</a> without any success.</p>
  
  <p>I understand that forcing <code>onBindViewHolder()</code> on all elements would work against the <a href="https://stackoverflow.com/a/37524217/1510725">whole purpose of the RecycleView.Adapter</a>. Thus, I am open to any other suggestions on how I can catch that <code>TextView</code> reference.</p>
  
  <p>As a temporary fix to this problem, I am able to use a try catch block around the method that generates the <code>NullPointerException</code>. However, I am concerned that the lack of the reference means I could introduce errors in the future.</p>