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 8403843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:26:47+00:00 2026-06-09T22:26:47+00:00

I use a PagerAdapter . I have a lot of elements so I don’t

  • 0

I use a PagerAdapter. I have a lot of elements so I don’t load all elements in the same time. I reload the adapter, I change the old elements by the new elements. For example I have 4 elements, when I arrive at the last element, I reload the elements and I call setCurentItem(1) to be able to show the viewpager in position one. I have done a lot of tests. I put:

viewPager.setCurrentItem(1,false); //But not scroll, put drastically the new page.
viewPager.setCurrentItem(1);

I have tried to modify onPageScrollStateChanged(int arg0), I only have 3 views and always ubicate in the middle.

if (arg0 == ViewPager.SCROLL_STATE_DRAGGING) {
    if(focusedPage==2) {
        //Modify adapter
        viewPager.setCurrentItem(1,false);   

    }else if(focusedPage==0){
        //Modify adapter
        viewPager.setCurrentItem(1,false);
    } 

And I have tryed to modify onPageSelected(int arg0)

focusedPage=arg0;

Using this last example I have scroll the views immediately but always it located on the last page.
Anybody know how I can slide.

Thank you

  • 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-09T22:26:48+00:00Added an answer on June 9, 2026 at 10:26 pm

    Can I know more about the background of what you are trying to accomplish?

    Anyway, from what I can understand you are trying to make an “infinite” ViewPager going from the last one to the first and vice versa (please correct me if I am wrong). And you want your ViewPager to go to the first page but scrolling – not just appearing from nowhere.

    Well, if you disable the smooth scroll (the second parameter), then it will go directly to the page you want with no scroll motion (and will not “change” to the other pages on the way), and if you enable the smooth scroll then it will go through all the views, so you will see how it was not the next one but the first one.

        /*No swipe animation, and no onPageChanged for the page in the middle*/
        mPager.setCurrentItem(1, false); 
    
        /*The same as if you do not add the second parameter*/
        mPager.setCurrentItem(1, true);
    
        /*Your ViewPager scrolls through all the needed views until it arrives at that view.*/
        mPager.setCurrentItem(1);
    

    What I can recommend to you with this in mind is that you can try to add “dummy” view at positions 0 and “last” and the view in position 0 would be the same as position “last – 1” and the “last” view would be the same as position “1”. So you will do everything normal, EXCEPT that on the OnPageChangeListener you will check if the current page is the position “0” or “last” and if it is, you will call setCurrentItem(“1”, false) or setCurrentItem(“last – 1”, false) depending on which position you are at now. In this way you will keep the “page change” effect while accomplishing what you want.

    I hope this can help you with your problem.

    NOTE:
    It may have a laggy change after you arrive at the new position, because it will have to load the view for the current, next and last views (or if you are on 4.0+ then it will load only the actual position).

    UPDATE:

    If you change the content of the List/Array that determines the content of the ViewPager, you need to call:

    ViewPager mPager = new ViewPager();
    mPager.getAdapter().notifyDataSetChanged();  //This notify that you need to recreate the views
    
    /*This is if you want to change the data and then go to a specific position
    If you do not do this you will have a very Buggy Behavior*/
    new Handler().post(new Runnable() {
    @Override
    public void run() {
        mPager.setCurrentItem(2); //Where "2" is the position you want to go
        }
    });
    

    UPDATE 2:

    Why do you not add all your elements to the ViewPager? the ViewPager already has optimization for handling those cases, in my case I have a lot of elements in it and it is working like a charm.

    Another thing, in your code I see you change to the middle page each time a page is “settling”. But then you really never show the right and left view, so why do you have them?

    Last thing, when you change your dataset you need to call the “notifyDataSetChanged” method that I mentioned above, and then you call the “setCurrentItem” method inside a handler. If you don’t, your app will not work as expected.

    UPDATE 3:

    Well, the only thing I can recommend is having a List where you keep adding the new objects that you bring from the database, and then as long as you keep inserting objects to the end of the List there is no problem. If you want to add objects in the middle or at the beginning then you need to call the notifyDataSetChanged but that is going to be kind of slow because it will generate the views again. We do it this way and it works perfectly and we even download the info from a server, the data is not local (And actually we add info to the end and beginning of the List).

    If you have any other questions about how to achieve this do not hesitate to ask.

    UPDATE 4:

    Just in case anyone is actually looking for a circular ViewPager, I added a proof of concept code that you can re-use. It works without problem and I have used it with complex views and there is still no lag whatsoever.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which uses ViewPager. Inside the ViewPager I don't use Fragments,
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;
In ViewPagerAdapter.class I have 2 layout(whereami.xml and mapview.xml), and use LayoutInflater to inflate each
Use Elixir and have two entities -- Voter and Candidate -- with many to
use javascript or other method ? have any recommendation?
Use case is to have a server connect to thousands of users email accounts
use case example I have a servlet that is receiving login requests. If a
With the help of this tutorial I have created a PagerAdapter for my Android
so I have run now with this problem when trying to use FragmentStatePagerAdapter with

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.