Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:48:14+00:00 2026-06-07T22:48:14+00:00

Possible Duplicate: ViewPager as a circular queue / wrapping I have three fragment classes

  • 0

Possible Duplicate:
ViewPager as a circular queue / wrapping

I have three fragment classes in my code.
FirstActivity,SecondActivity,ThirdActivity i want to swipe these three activities.. these three are extend from Fragment class

public class ViewPagerFragmentActivity extends FragmentActivity {
private PagerAdapter mPagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.viewpager_layout);
    initialisePaging();
    }

/**
 * Initialize the fragments to be paged
 */
List<Fragment> fragments = new Vector<Fragment>();
ViewPager pager;
private void initialisePaging() {
    fragments.add(Fragment.instantiate(this, FirstActivity.class.getName()));
    fragments.add(Fragment.instantiate(this, SecondActivity.class.getName()));
    fragments.add(Fragment.instantiate(this, ThirdActivity.class.getName()));
    this.mPagerAdapter = new MyPagerAdapter(super.getSupportFragmentManager(), fragments);
    pager = (ViewPager) super.findViewById(R.id.viewpager);
    pager.setAdapter(this.mPagerAdapter);

}

}

and here is my FragmentPageAdapter class

public class MyPagerAdapter extends FragmentPagerAdapter {

private final List<Fragment> fragments;


public MyPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
    super(fm);
    this.fragments = fragments;
}


@Override
public Fragment getItem(int position) {
    System.out.println("position"+position);
    return this.fragments.get(position);
}


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

}

my code is working in this way A<->B<->c
but my requirement is to run like this wayC<->A<->B<->C<-A->
that is in circular fragments are swipable…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:48:16+00:00Added an answer on June 7, 2026 at 10:48 pm

    Circular ViewPager is possible.
    With the help of ViewPager as a circular queue / wrapping this link have coded like this. Hope it helps what you needed.

    The CircluarPagerAdapter class:

    >

     public class CircularPagerAdapter extends PagerAdapter{
    
    private int[] pageIDsArray;
    private int count;
    
    public CircularPagerAdapter(final ViewPager pager, int... pageIDs) {
        super();
        int actualNoOfIDs = pageIDs.length;
        count = actualNoOfIDs + 2;
        pageIDsArray = new int[count];
        for (int i = 0; i < actualNoOfIDs; i++) {
            pageIDsArray[i + 1] = pageIDs[i];
        }
        pageIDsArray[0] = pageIDs[actualNoOfIDs - 1];
        pageIDsArray[count - 1] = pageIDs[0];
    
        pager.setOnPageChangeListener(new OnPageChangeListener() {
    
            public void onPageSelected(int position) {
                int pageCount = getCount();
                if (position == 0){
                    pager.setCurrentItem(pageCount-2,false);
                } else if (position == pageCount-1){
                    pager.setCurrentItem(1,false);
                }
            }
    
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                // TODO Auto-generated method stub
            }
    
            public void onPageScrollStateChanged(int state) {
                // TODO Auto-generated method stub
            }
        });
    }
    
    public int getCount() {
        return count;
    }
    
    public Object instantiateItem(View container, int position) {
        LayoutInflater inflater = (LayoutInflater) container.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        int pageId = pageIDsArray[position];
        View view = inflater.inflate(pageId, null);
        ((ViewPager) container).addView(view, 0);
        return view;
    }
    
    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }
    
    @Override
    public void finishUpdate(View container) {
        // TODO Auto-generated method stub
    }
    
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((View) object);
    }
    
    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // TODO Auto-generated method stub
    }
    
    @Override
    public Parcelable saveState() {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public void startUpdate(View container) {
        // TODO Auto-generated method stub
    }
    }
    

    and this is your main class:

    >

    public class MainActivity extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        ViewPager myPager = (ViewPager) findViewById(R.id.conpageslider);
        PagerAdapter adapter = new CircularPagerAdapter(myPager, new int[]{R.layout.first_activity, R.layout.second_activity, R.layout.third_activity});
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(3);
    
    
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: C#: How to reference generic classes and methods in xml documentation I
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: How to successfully rewrite old mysql-php code with deprecated mysql_* functions? I
Possible Duplicate: Unload a module in Python After importing Numpy, lets say I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.