0

In my project I have used a viewpager with 3 pages in it. Now in the first page I have a next button. So first time when I am in first page, we should not allow swipe until next button is clicked. When next button is clicked we can come back to first page by swiping. So we should allow swipe from page 2 to page 1. Similarly i have a next button in page2. So there also first time when i am in page2, using swipe it should not allow to go to page 3. Only after clicking on next button in page2, then it will go to page3. From page 3 it should allow swipe to go to page 2 and page1. How can I achieve this. I am trying from past two weeks using some custom view pager classes available in internet tutorials but none of them worked for me as per the requirement.

My Code:

public class PagerFragment : Android.Support.V4.App.Fragment
    {

        public static ViewPager pager;

        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your fragment here
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.pager_layout, container, false);

            pager = view.FindViewById<ViewPager>(Resource.Id.viewPager);
            TabLayout tabLayout = view.FindViewById<TabLayout>(Resource.Id.tab_layout);                       
            pager.Adapter = new PagerAdapter(ChildFragmentManager);

            tabLayout.SetupWithViewPager(pager, true):
return view;

}

pagerlayout.axml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_marginTop="60dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorAccent" />
    <LinearLayout
        android:id="@+id/mainLinearlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/lin_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp">
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginTop="14dp"
                android:text="title"
                android:textStyle="bold"
                android:textColor="#ffffff"
                android:textSize="12sp" />
            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:tabMode="fixed"
                app:tabBackground="@drawable/tab_selector"
                app:tabIndicatorHeight="0dp" />
        </LinearLayout>
</LinearLayout>

Please help me on this. Will be really thankful

Amrutha
  • 575
  • 4
  • 9
  • 29
  • I can give you a control but you need to write the logic for the above scenario – FreakyAli Feb 15 '19 at 04:38
  • You should create a custom view pager as shown here https://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s – Nongthonbam Tonthoi Feb 16 '19 at 05:32

0 Answers0