To stop specific tab from being selected just use customized TabLayout
and ViewPager
you can even use the tab for other purposes this way.
public class CustomViewPager extends ViewPager {
private float initialXValue;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event)
{
if(event.getAction()==MotionEvent.ACTION_DOWN)
initialXValue = event.getX();
return this.isSwipeAllowed(event) && super.onInterceptTouchEvent(event);
}
private boolean isSwipeAllowed(MotionEvent event) {
//you can prevent any swipe from right to left for an item at a specified index, in your case getCurrentItem() returns 3 for Event tab
return getCurrentItem()!=3 || event.getAction() != MotionEvent.ACTION_MOVE || (event.getX() - initialXValue) > 0;
}
}
Custom TabLayout
public class CustomTabLayout extends TabLayout {
public CustomTabLayout(Context context,AttributeSet attrs) {
super(context, attrs);
}
public CustomTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void selectTab(Tab tab, boolean updateIndicator) {
// it doesn't allow the item on index 3 to be selected in anyway
if (!(tab.getPosition() == 3))
super.selectTab(tab, updateIndicator);
}
}