title: How to programmatically detect when an item is visible in a RecyclerView?
body: <p>My Android app has a RecyclerView with PagerSnapHelper. Each item has width and height as <code>match_parent</code>. Thus, only 1 view item stays on the page. I am interested in knowing when a particular view item is fully visible to the user. I want to perform some operation on that view.</p>
  
  <h2>More Details</h2>
  
  <p>I am displaying charts in each view item using <a href="https://github.com/PhilJay/MPAndroidChart" rel="noreferrer">MpAndroidChart</a> library. I am also animating those charts. But since the RecyclerView loads some view items which are just adjacent to the currently visible view items, the animation happens before the view is even visible to the user. Thus, I need a callback method to surely know that a particular view item is visible to the user. So that I can animate my chart at that time.</p>
  
  <h2>Code</h2>
  
  <p>I tried the following way to know for sure what's the currently visible item view. But it didn't solve my issue:</p>
  
  <pre><code>recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
      @Override
      public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
          super.onScrollStateChanged(recyclerView, newState);
          if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
              View centerView = snapHelper.findSnapView(linearLayoutManager);
              BarChart barChart = centerView.findViewById(R.id.barChart);
              barChart.animateXY(ChartUtil.TIME, ChartUtil.TIME);
          }
      }
  });
  </code></pre>
  
  <h2>Edit 1</h2>
  
  <p>The only known callback method for implementing the logic for each item view of a RecyclerView is <code>onBindViewHolder</code>. But the issue is if currently visible item position is (suppose) x, then RecyclerView also loads x+1 in advance so that the scrolling remains smooth. Due to this, the logic of animating the item view (in my case) is also getting executed before the view is even visible to the user. Thus, I need a callback method which tells me x position (or) item view is "visible" to the user.</p>
  
  <p>Any help will be greatly appreciated!</p>