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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:42:16+00:00 2026-06-07T13:42:16+00:00

This is my first post here and my first try to explain a coding

  • 0

This is my first post here and my first try to explain a coding problem in english.. So please stay gentle while reading this :).

I have two questions about the ViewPager.

First:

If I pass a List of Fragments to the PagerAdapter it will show the first Fragment in the List. Is it possible to modify this to be able to show the 2nd, 3rd… Fragment in the List first? Because the method setCurrentItem(page) will show the page after the first fragment was displayed by the PagerAdapter.

Second:

I tried to implement a pause between a dynamic ViewChange like this:

// pass the Fragments to pagerAdapter here which will show the first fragment

// loop for the other Fragments
handler.postDelayed(new Runnable(){
    public void run(){
       for(int i = 0; i < list.size(); i++){
            ViewPager.setCurrentItem(list.indexOf(i), true);
            // Set Pause here
       }
    }
}, 500);

The comment “set pause here” marks the location where I’m still trying to pause between the paging. But i don’t know how to solve this. Because Thread.sleep isn’t the real deal here.

The idea was to display the first Fragment with the PageAdapter. Then I use handler.postDelayed to delay the second page swipe. And in this I’m looping through all pages with a constant delay.

I would be really happy if someone could help me to find a solution for these.

  • 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-07T13:42:19+00:00Added an answer on June 7, 2026 at 1:42 pm

    For your first question, are you calling setCurrentItem(int, false)? If you just call setCurrentItem(int), the ViewPager will animate the transition if it has already been through its first layout with its current adapter. If that’s not a solution, maybe consider initializing the ViewPager with visibility = "invisible" in your layout file (or alternatively make a call to setVisibility(View.INVISIBLE) prior to passing the fragment list to the PagerAdapter.) Then, after you call setCurrentItem, you can set the ViewPager back to visible using setVisibility(View.VISIBLE). I would think that setting the ViewPager up in onCreate and calling setCurrentItem(int, false) should prevent any animations from appearing, but I don’t have time to test right now.

    For the second problem, I think the part that is tripping you up is that the run method is going to block the entire UI thread while it’s running, which means that the UI won’t be able to update itself while you are looping through the items in the ViewPager.

    In essence, you are calling Thread.sleep() on the UI thread. That may not be totally clear since it’s inside the Runnable’s run method unless you realize that you have posted a message to run on the Handler’s Thread, which will be the UI thread if you created it in an Activity life cycle method using the default Handler() constructor. Instead, you want your posted Runnable to postDelayed a new message for the next time you want to change the current item in the ViewPager.

    What I would do is something like the following (caveat – I haven’t tested this):

    Subclass Handler to add a method to continuously loop (I am assuming you are doing this as an inner class on the Activity that holds the ViewPager so you get access to the member variable containing the ViewPager. I’m calling that member variable mPager in the code below):

    private Runnable mLoopingRunnable = new Runnable(){
        public void run() {
            int currentItem = mPager.getCurrentItem();
            int totalItems = mPager.getAdapter().getCount();
            int nextItem = (currentItem + 1) % totalItems;
            mPager.setCurrentItem(nextItem, true);
                    handler.postDelayed(self, 500);
                }
            };
    
    handler.postDelayed(mLoopingRunnable, 500);
    

    If/when you want to stop looping (note that you’ll need to keep a handle to the Runnable if you want to cancel it at some point):

    handler.removeCallbacks(mLoopingRunnable);
    

    Note that one advantage of changing calling setCurrentItem as I have above is that it won’t interfere with the user swiping the ViewPager to move from one view to the next. If you just set the currentItem to some integer like you did in your loop, the behavior will appear somewhat strange when the user has interacted with the pager.

    I would have guessed that there was be something to handle the looping automatically similar to ViewFlipper, but it’s not readily apparent that there is from a cursory look at the ViewPager API.

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

Sidebar

Related Questions

This is my first post here. I have a problem. I need to take
This is my first post here. I have been reading posts here since I
this is my first post here. I'll try to get to the point quickly,
This is my first post here - so be gentle :-) I want to
this is my first time to post a question here, I will try to
This is my first post, so please bear with me. I'll try and be
this is my first post here on stackoverflow and am very impressed by the
My first post here, so i hope this is the right area. I am
I'm new to Java and this is my first post on here so hopefully
This is my first time here so I hope I post this question at

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.