title: disable swiping between tabs in FragmentActivity
body: <p>I have a (Sherlock)FragmentActivity with 2 tabbed fragments.  The left fragment is a GridView that displays pictures of an album and the right fragment consists of a ViewPager that is used to view individual pictures.  From the left fragment you can scroll through the pictures and select one.  Tabbing (or swiping) over to the right fragment will show the picture and because it is a ViewPager you can swipe to the preceding or the next picture.</p>
  
  <p>This works great except that the FragmentActivity wants to intercept the right swipe and move back to the left tab.  I would like to prevent the FragmentActivity from intercepting the swipes when I am on the right tab.  If I had to disable swiping between tabs altogether it would be satisfactory.  I just want the swiping to be dedicated to the current tab and not be used to move between tabs.</p>
  
  <p>The following images indicate the current behavior.  The right image shows what happens when I do a swipe to the right.  As you can see the left tab starts to appear.  I want the swipe to instead apply to the right tab only so that I can swipe between the images without the left tab appearing.</p>
  
  <p><img src="https://i.stack.imgur.com/FAURl.jpg" alt="enter image description here"></p>
  
  <p>I see solutions to control swiping within a ViewPager but have yet to find a solution to control swiping between tabbed fragments.</p>
  
  <p>Here is the xml for the GridView fragment and the ViewPager fragment:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"&gt;
    &lt;FrameLayout android:id="@android:id/tabcontent"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"&gt;
      &lt;GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/gridview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:columnWidth="100dip"
                android:gravity="center"
                android:horizontalSpacing="4dip"
                android:numColumns="auto_fit"
                android:stretchMode="columnWidth"
                android:verticalSpacing="4dip" /&gt;
    &lt;/FrameLayout&gt;
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"&gt;
  
    &lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
                                       android:id="@+id/pager"
                                       android:layout_width="fill_parent"
                                       android:layout_height="0px"
                                       android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here a code summary of the ViewPager fragment:</p>
  
  <pre><code>public class FragmentFlash extends SherlockFragment {
  
     private GestureDetector gestureDetector;
     View.OnTouchListener gestureListener;
     private ViewPager pager = null;
     private int pagerPosition;
  
     @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pagerPosition = 0;
        // Gesture detection
        gestureDetector = new GestureDetector(new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
              public boolean onTouch(View v, MotionEvent event) {
                 return gestureDetector.onTouchEvent(event);
              }
           };
        }
  
     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.flash, container, false);
        pager = (ViewPager) v.findViewById(R.id.pager);
        pager.setOnTouchListener(gestureListener);
        return v;
     }
  
     class MyGestureDetector extends SimpleOnGestureListener {
        private static final int SWIPE_MIN_DISTANCE = 10;
        private static final int SWIPE_MAX_OFF_PATH = 250;
        private static final int SWIPE_THRESHOLD_VELOCITY = 50;
  
        @Override
           public boolean onDown(MotionEvent e) {
           return true;//false; make onFling work with fragments
        }
  
        @Override
           public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
           try {
              if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH)
                 return false;
              else
                 // right to left swipe
                 if(distanceX &gt; SWIPE_MIN_DISTANCE) {
                    if (pagerPosition &lt; imageUrls.length-1)
                       pager.setCurrentItem(++pagerPosition);
                 // left to right swipe
                 } else if (distanceX &lt; -SWIPE_MIN_DISTANCE) {
                    if (pagerPosition &gt; 0)
                       pager.setCurrentItem(--pagerPosition);
                 }
              return true;
           } catch (Exception e) {
              // nothing
           }
           return false;
        }
     }
  
     private class ImagePagerAdapter extends PagerAdapter {
  
        private String[] images;
        private LayoutInflater inflater;
  
        ImagePagerAdapter(String[] images) {
           this.images = images;
           inflater = mContext.getLayoutInflater();
        }
  
        @Override
           public void destroyItem(View container, int position, Object object) {
           ((ViewPager) container).removeView((View) object);
        }
  
        @Override
           public void finishUpdate(View container) {
        }
  
        @Override
           public int getCount() {
           return images.length;
        }
  
        @Override
           public Object instantiateItem(View view, int position) {
           final View imageLayout = inflater.inflate(R.layout.item_pager_image, null);
           final ImageView imageView = (ImageView)   imageLayout.findViewById(R.id.image);
           final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
  
           byte[] image = ;//get byte array from file at images[position];
           if (null != image) {
              Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length);
              imageView.setImageBitmap(bitmap);
           }
           ((ViewPager) view).addView(imageLayout, 0);
  
           return imageLayout;
        }
  
        @Override
           public boolean isViewFromObject(View view, Object object) {
           return view.equals(object);
        }
  
        @Override
           public void restoreState(Parcelable state, ClassLoader loader) {
        }
  
        @Override
           public Parcelable saveState() {
           return null;
        }
  
        @Override
           public void startUpdate(View container) {
        }
     }
  
     public void pagerPositionSet(int pagerPosition, String[] imageUrls) {
        Log.i(Flashum.LOG_TAG, "FragmentFlash pagerPositionSet: " + pagerPosition);
        if (pagerPosition &gt;= 0)
           this.pagerPosition = pagerPosition;
        if (pager != null) {
           pager.setAdapter(new ImagePagerAdapter(imageUrls));
           pager.setCurrentItem(this.pagerPosition);
        }
     }
  
  }
  </code></pre>
  
  <p>This is the item_pager_image.xml:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="1dip" &gt;
  
      &lt;ImageView
          android:id="@+id/image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:adjustViewBounds="true"
          android:contentDescription="@string/descr_image" /&gt;
  
      &lt;ProgressBar
          android:id="@+id/loading"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:visibility="gone" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>