Okay so after vaguely wandering for about a week, I found a workaround solution to validate the inputs, meanwhile also preventing swipes.
Step 1: First thing is to implement a Custom View Pager class as
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Toast;
public class FirstRunPager extends ViewPager {
private boolean isPagingEnabled;
public Context context;
public FirstRunPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.isPagingEnabled = true;
this.context = context;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isPagingEnabled) {
return super.onTouchEvent(event);
}
Toast.makeText(context, "Please fill in the details, then swipe !",
Toast.LENGTH_LONG).show();
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (isPagingEnabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean b) {
isPagingEnabled = b;
}
}
Step 2: So now i can prevent swipes just by setting is paging enabled false, meanwhile any touch events are responded by a Toast, which prompts user to fill all fields.
Step 3: After a fragment is visible
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
if (isVisibleToUser) {
// set isPagingEnabled false here
// validate EditText values here using Text Watcher
// if all okay
// set isPagingEnabled = true
// tell the user through a Toast, that he can swipe now.
}
}
That's how I'm implementing validation right now. I will update it if I improve my code.