title: Android custom ViewPager is not allowing me to click on the View components
body: <p>I am using a FragmentStatePagerAdapter with a custom ViewPager. Previously I was using a standard ViewPager and I was able to swipe to all my fragments correctly and interact with the EditTexts/Buttons and other components on the different Views, however I had to create a custom ViewPager when restricting the swipe direction.
  Once I used the custom ViewPager, everything displays correctly etc however I am unable to click any of the EditTexts/Buttons etc.</p>
  
  <p>Can anyone see the problem with this? I am assuming the SignUpPager is not overriding a certain method or incorrectly handling the MotionEvent.... but none of my attempts have worked.</p>
  
  <p>SignUpPager.java:</p>
  
  <pre><code>import android.content.Context;
  import android.support.v4.view.ViewPager;
  import android.util.AttributeSet;
  import android.view.MotionEvent;
  
  
  public class SignUpPager extends ViewPager{
      public SignUpPager(Context context){
          super(context);
      }
  
      public SignUpPager(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      private float initialXValue;
      public SwipeDirection direction = SwipeDirection.all;
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          if (this.IsSwipeAllowed(event)) {
              return super.onTouchEvent(event);
          }
  
          return false;
      }
  
      @Override
      public boolean onInterceptTouchEvent(MotionEvent event) {
          if (this.IsSwipeAllowed(event)) {
              return super.onTouchEvent(event);
          }
          return false;
      }
  
      private boolean IsSwipeAllowed(MotionEvent event) {
          if(this.direction == SwipeDirection.all) return true;
  
          if(direction == SwipeDirection.none )//disable any swipe
              return false;
  
          if(event.getAction()==MotionEvent.ACTION_DOWN) {
              initialXValue = event.getX();
              return true;
          }
  
          if(event.getAction()==MotionEvent.ACTION_MOVE) {
              try {
                  float diffX = event.getX() - initialXValue;
                  if (diffX &gt; 0 &amp;&amp; direction == SwipeDirection.right ) {
                      // swipe from left to right detected
                      return false;
                  } else if (diffX &lt; 0 &amp;&amp; direction == SwipeDirection.left ) {
                  // swipe from right to left detected
                  return false;
                  }
              } catch (Exception exception) {
                  exception.printStackTrace();
              }
          }
  
          return true;
      }
  
      public enum SwipeDirection {
          all, left, right, none ;
      }
  }
  </code></pre>
  
  <p>In MainActivity.java I connect the SignUpPager to a FragmentStatePagerAdapter (note I have just copied the critical lines of code for this part):</p>
  
  <pre><code>public SignUpAdapter signUpAdapter;
  public static SignUpPager pager;
  
  signUpAdapter = new SignUpAdapter(getSupportFragmentManager());
  pager = (SignUpPager) findViewById(R.id.signUpViewPager);
  pager.setAdapter(signUpAdapter)
  
  public static class SignUpAdapter extends FragmentStatePagerAdapter{
   ..........
  }
  </code></pre>
  
  <p>sign_up.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;signUp.SignUpPager
          android:id="@+id/signUpViewPager"
          android:layout_width="match_parent"
          android:layout_height="0px"
          android:layout_weight="1"
      /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>fragment_view.xml (this is the XML for the view of which I am unable to click the components) :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/signUpLayout"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/holo_orange_dark"
  tools:context="com.example.tabbyreyez.helloworld.SignUpSecondaryController"&gt;
  
     &lt;TextView
          android:id="@+id/signUpDataTitle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/signUpData"
          android:layout_marginTop="30dp"
          android:layout_marginLeft="27dp"
          android:textSize="35dp"/&gt;
  
      &lt;TextView
          android:id="@+id/firstNameLabel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="First Name:"
          android:layout_below="@+id/signUpDataTitle"
          android:layout_marginTop="30dp"
          android:layout_marginLeft="10dp"
          android:textSize="17dp"/&gt;
  
      &lt;EditText
          android:id="@+id/firstName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:inputType="textPersonName"
          android:hint="e.g. Tabraiz"
          android:layout_below="@+id/signUpDataTitle"
          android:layout_marginTop="18dp"
          android:layout_marginLeft="130dp"
          android:ems="9"/&gt;
  
      &lt;TextView
          android:id="@+id/lastNameLabel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Last Name:"
          android:layout_below="@+id/firstNameLabel"
          android:layout_marginTop="23dp"
          android:layout_marginLeft="10dp"
          android:textSize="17dp" /&gt;
  
      &lt;EditText
          android:id="@+id/lastName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:inputType="textPersonName"
          android:hint="e.g. Malik"
          android:layout_below="@+id/firstName"
          android:layout_marginLeft="130dp"
          android:ems="9" /&gt;
  
      &lt;Button
          android:id="@+id/signUpButton"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:text="Sign Up"
          android:layout_below="@+id/passwd"
          android:layout_centerHorizontal="true"
      /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>