title: Android: how to disable swiping between tablayout control by button click
body: <p>i have 2 fragment in my tab layout, i manage to disable the swiping function between tab layout by button click. How to implement the disable function in my onclick button. thanks for advance</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener{
  
  
  private TabLayout tabLayout;
  
  private ViewPager viewPager;
  int ans =2;
  
   ------FCViewPager disable;------
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  
      BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
      Tab1 tab1 = new Tab1();
      Tab2 tab2 = new Tab2();
  
  
      adapter.addFragment(tab1, "1");
      adapter.addFragment(tab2, "2");
  
      viewPager = (ViewPager) findViewById(R.id.pager);
  
  
      viewPager.setAdapter(adapter);
  
  
      tabLayout.setOnTabSelectedListener(this);
      tabLayout.setupWithViewPager(viewPager);
      tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
      tabLayout.setupWithViewPager(viewPager);
  
  }
  </code></pre>
  
  <p>----- public void testing( View view) {</p>
  
  <pre><code>        disable.setEnableSwipe(false);
  
  }---------
  @Override
  public void onTabSelected(TabLayout.Tab tab) {
      viewPager.setCurrentItem(tab.getPosition());
  }
  
  @Override
  public void onTabUnselected(TabLayout.Tab tab) {
  
  }
  
  
  @Override
  public void onTabReselected(TabLayout.Tab tab) {
  
  }
  public class BasePagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
      public BasePagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  
  
      public void removeFragment(int position) {
          mFragmentTitleList.remove(position);
          mFragmentList.remove(position);
          notifyDataSetChanged();
  
      }
      public void addFragment(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
      @Override
      public int getItemPosition(Object object) {
          return POSITION_NONE;
      }
  
  }
  </code></pre>
  
  <p>Tab1</p>
  
  <pre><code> public class Tab1 extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View h = inflater.inflate(R.layout.tab1, container, false);
  
      return  h;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Tab2</p>
  
  <pre><code>public class Tab2 extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View h = inflater.inflate(R.layout.tab2, container, false);
          return h;
      }
  </code></pre>