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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:22:38+00:00 2026-06-09T21:22:38+00:00

The following code scrolls the 4 pages just fine. My problem is that the

  • 0

The following code scrolls the 4 pages just fine. My problem is that the onPageScrolled event does not get triggered when the pages are scrolled. This occurs whether or not I use the myPager.SetOffsccreenPageLimit(4) command. After reading the docs, it is my understanding that when I have implements ViewPager.OnPageChangeListener included in the MyPagerAdapter class that the event should be triggered. What am I doing wrong?

Thanks,
Gary Blakely

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MyPagerAdapter adapter = new MyPagerAdapter();
    ViewPager myPager = (ViewPager) findViewById(R.id.mysevenpanelpager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(0);
    myPager.setOffscreenPageLimit(4);
}

private class MyPagerAdapter extends PagerAdapter 
    implements ViewPager.OnPageChangeListener {

    public int getCount() {
        return 4;
    }

    public Object instantiateItem(View collection, int position) {
        LayoutInflater inflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        int resId = 0;
        switch (position) {
        case 0:
            resId = R.layout.left;
            break;
        case 1:
            resId = R.layout.gps;
            break;
        case 2:
            resId = R.layout.map;
            break;
        case 3:
            resId = R.layout.right;
            break;
        }

        View view = inflater.inflate(resId, null);

        ((ViewPager) collection).addView(view, 0);

        return view;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);
    }
    @Override
    public void onPageScrollStateChanged(int arg0) {
        int myint = 9;
        myint = myint * 2;
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {
        int myint = 9;
        myint = myint * 2;
    }

    @Override
    public void onPageSelected(int arg0) {
        int myint = 9;
        myint = myint * 2;
    }
}
  • 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-09T21:22:40+00:00Added an answer on June 9, 2026 at 9:22 pm

    You also need to set the listener using setOnPageChangeListener().

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MyPagerAdapter adapter = new MyPagerAdapter();
        ViewPager myPager = (ViewPager) findViewById(R.id.mysevenpanelpager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(0);
        myPager.setOffscreenPageLimit(4);
        myPager.setOnPageChangeListener(adapter); // This line here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
Following code is a pretty simple and complete JQuery Dialog. Everything works. Problem is
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
Update: I left the following javascript code in to show how the problem developed
I have the following code to scroll images in vertical direction (uses jCarouselLite )
I use the following code to load an image into an scroll view. The
if have the following code: <div id=container style=position:relative; width:300px; height:300px; overflow:scroll;> <div id=header> </div>
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
Following code: <%= render 'shared/error_messages', f.object %> where f.object is instance of a class

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.