title: SwipeRefreshLayout with vertical view pager to only refresh on the topmost fragment
body: <p>I've tried to implement <code>swiperefreshlayout</code> in my code but it keeps refreshing the entire pager instead of just refreshing when i'm on the first <code>Fragment</code> i.e the 0th <code>Fragment</code>.
  I tried setting refresh to false as shown, but the loader still appears, and doesn't reset when I go back to the 0th <code>Fragment</code> again.
  On setting <code>swiperefreshlayout.enable(false)</code>, I can't refresh it anywhere.
  Can anyone suggest an alternative?
  This is my <code>XML</code> file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/parentLinearLayout"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity" &gt;
  
      &lt;android.support.v4.widget.SwipeRefreshLayout
          android:id="@+id/swipe_refresh_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
          &lt;ScrollView
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:fillViewport="true"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"&gt;
              &lt;lbbdapp.littleblackbook.com.littleblackbook.Support.VerticalViewPager
                  android:id="@+id/verticalViewPager"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content" /&gt;
              &lt;/LinearLayout&gt;
          &lt;/ScrollView&gt;
      &lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And this is my activity:</p>
  
  <pre><code>public class FeedActivity extends ActionBarActivity {
  
  PageAdapter mPageAdapter;
  ProgressBar mProgressBar;
  ProgressDialog prog;
  ViewPager pager;
  String article_id;
  private float x1, x2;
  SwipeRefreshLayout mSwipeRefreshLayout;
  
  ArrayList&lt;FragmentObject&gt; mObjectsDataList;
  ArrayList&lt;ArticleObject&gt; mArticleDataList=new ArrayList&lt;ArticleObject&gt;();
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.feed_layout);
      mObjectsDataList = new ArrayList&lt;FragmentObject&gt;();
  
      DataFetcherTask myTask = new DataFetcherTask();
      myTask.execute();
  
      mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
      mSwipeRefreshLayout.setColorScheme(android.R.color.holo_blue_bright,
              android.R.color.holo_blue_dark,
              android.R.color.holo_purple,
              android.R.color.darker_gray);
      pager=(ViewPager)findViewById(R.id.verticalViewPager);
  
  
  
      mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
  
              if(pager.getCurrentItem()==0) {
                  Log.wtf("current item is 0", "0");
                  mSwipeRefreshLayout.setRefreshing(true);
                  Log.wtf("Swiping", "Refreshing");
                  (new Handler()).postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          mSwipeRefreshLayout.setRefreshing(false);
                          DataFetcherTask myTask = new DataFetcherTask();
                          myTask.execute();
                      }
                  }, 3000);
  
              }
              else{
                  mSwipeRefreshLayout.setRefreshing(false);
  
              }
          }
  
      });
  
  
  }
  </code></pre>
  
  <p>This is my vertical <code>ViewPager</code>:</p>
  
  <pre><code>public class VerticalViewPager extends ViewPager {
  
  public VerticalViewPager(Context context) {
      super(context);
      init();
  }
  
  public VerticalViewPager(Context context, AttributeSet attrs) {
      super(context, attrs);
      init();
  }
  
  private void init() {
      // The majority of the magic happens here
      setPageTransformer(true, new VerticalPageTransformer());
      // The easiest way to get rid of the overscroll drawing that happens on the left and right
      setOverScrollMode(OVER_SCROLL_NEVER);
  }
  
  private class VerticalPageTransformer implements ViewPager.PageTransformer {
  
      @Override
      public void transformPage(View view, float position) {
  
          if (position &lt; -1) { // [-Infinity,-1)
              // This page is way off-screen to the left.
              view.setAlpha(0);
  
          } else if (position &lt;= 1) { // [-1,1]
              view.setAlpha(1);
  
              // Counteract the default slide transition
              view.setTranslationX(view.getWidth() * -position);
  
              //set Y position to swipe in from top
              float yPosition = position * view.getHeight();
              view.setTranslationY(yPosition);
  
          } else { // (1,+Infinity]
              // This page is way off-screen to the right.
              view.setAlpha(0);
          }
      }
  }
  
  /**
   * Swaps the X and Y coordinates of your touch event.
   */
  private MotionEvent swapXY(MotionEvent ev) {
      float width = getWidth();
      float height = getHeight();
  
      float newX = (ev.getY() / height) * width;
      float newY = (ev.getX() / width) * height;
  
      ev.setLocation(newX, newY);
  
      return ev;
  }
  
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev){
      boolean intercepted = super.onInterceptTouchEvent(swapXY(ev));
      swapXY(ev); // return touch coordinates to original reference frame for any child views
      return intercepted;
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
      return super.onTouchEvent(swapXY(ev));
    }
  
   }
  </code></pre>