Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
How to make a circular view pager2?

How can I make a circular view pager2(infinite-scrolling) in java? for example I wanna go from page 1to page 100 while swiping left and not to get stopped.

myViewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            Log.d(CPAct,"onPageScrolled "+position);
        }

        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            Log.d(CPAct,"onPageSelected Position: "+position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            super.onPageScrollStateChanged(state);
            Log.d(CPAct,"onPageScrollStateChanged  state: "+state);
          
            if (state == ViewPager2.SCROLL_STATE_IDLE) {
                if (myViewPager2.getCurrentItem() == 0)
                    myViewPager2.setCurrentItem(99, false);
                else if (myViewPager2.getCurrentItem() == 99) 
                    myViewPager2.setCurrentItem(0, false);
            }

I tried the code above in initView() after setting adapter but it doesn't work properly. for example when I swipe left from page 2, it directly goes to the last page and page 1 is skipped .The same thing happens when I swipe right to get to the last page and it directly goes to page 1. I just wanna make an infinite scrolling without skipping any pages.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you should post Adapters code, in there you should return Integer.MAX_VALUE in getCount and introduce proper fetching model for drawing list item - e.g. if you have ArrayList data then use data.get(position % data.getItemCount()) in getItem (as array have fixed size, but you are informing adapter about veeery large/infinite number of items)

your current aproach isn't good, as you are manipulating Views positions, this for shure will add some visual glitches sooner or later, and also is not very efficient

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!