当我滑动时,有没有办法阻止片段 1 进入片段 2?

Is there a way to stop a fragment 1 going to fragment 2 when I swipe?

有没有办法在我滑动时阻止片段 1 转到片段 2 right/left 我最近注意到,如果我向左滑动,我的片段会从 1 变为 2。

我在网上搜索但找不到答案

编辑:

我的适配器代码

    public ViewPager viewPager;
    private ViewPagerAdapter adapter



    adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.AddFragment(new Fragment_Sign_In_To_Firebase(), "Firebase Sign In");
    adapter.AddFragment(new Fragment_Create_Account(), "Create Account");
    adapter.AddFragment(new Fragment_Verify_Email(), "Verify Email");


    viewPager = (ViewPager) findViewById(R.id.viewpager_id_chat);
    viewPager.setAdapter(adapter);
    viewPager.arrowScroll(View.FOCUS_RIGHT);

ViewPaggerAdapter class:

public class ViewPagerAdapter extends FragmentPagerAdapter {

private final List<Fragment> lstFragment = new ArrayList<>();
private final List<String> lstTitles = new ArrayList<>();

public ViewPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    return lstFragment.get(position);
}

@Override
public int getCount() {
    return lstTitles.size();
}

@Override
public CharSequence getPageTitle(int position) {
    return lstTitles.get(position);
}

public void AddFragment(Fragment fragment, String title) {
    lstFragment.add(fragment);
    lstTitles.add(title);
}
}

我看到你的问题是没有正确查询你正在搜索的内容,我认为你在谈论 ViewPager

 public class CustomViewPager extends ViewPager {

    private boolean enabled;

    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.enabled = true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (this.enabled) {
            return super.onTouchEvent(event);
        }

        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (this.enabled) {
            return super.onInterceptTouchEvent(event);
        }

        return false;
    }

    public void setPagingEnabled(boolean enabled) {
        this.enabled = enabled;
    } }

在您的 XML

中使用它
<mypackage.CustomViewPager 
    android:id="@+id/myViewPager" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" />

或简单地添加此行

myViewPager.beginFakeDrag();