title: Android ViewPager/PagerAdapter with Data Binding and instantiateItem not executing active view
body: <p>I am using Android data binding in a MVVM framework.  I have a ViewPager setup with a corresponding PagerAdapter.  Some of the pages may contain videos. The issue that I am having is that the instantiateItem method in the PagerAdapter always executes the next view in the PagerAdapter instead of the current view.  For example say page 1 has no video, but page 2 does. When the user views page 1, the video in page 2 starts playing. Here is the instantiateItem method:</p>
  
  <pre><code>     public Object instantiateItem(ViewGroup container, int position) {     
          LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Service.LAYOUT_INFLATER_SERVICE);     
  
          ViewDataBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.main_layout, null, false);     
          Post post = posts.get(position);
          myViewModel = new PostModel(post);     
          binding.setVariable(BR.model, myViewModel);   
          container.addView(binding.getRoot());     
  
          return binding.getRoot();     
      }
  </code></pre>
  
  <p>How can I make the instantiateItem execute the current view instead of the next view? Is the issue related to setOffscreenPageLimit?</p>