0

I'm using Android Tutorial Bubbles library to add informative bubbles referring to views in my UI. My main UI consists of three tabs using a ViewPager. And I would like the tutorial for the second tab to begin only when the user navigates to that tab. I am able to catch the event that the user navigates to the tab using an OnPageChangeListener.

The problem is that the onPageSelected() method fires before the views are in their correct positions, meaning that the highlighted area that is supposed to surround the view of interest is significantly shifted. I could solve this using Thread.sleep() for a short period of time; is there a cleaner way of handling this?

Here's my code:

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (position == 1) {
                sensorReadingFragment.showTutorial();
            }
        }
    });
Sean
  • 445
  • 1
  • 5
  • 10

1 Answers1

0

Ok, you can delay it as

 pager.post(new Runnable() {
        @Override
        public void run() {
            pager.setCurrentItem(position_tab);
           // Perform your operations
        }
    });
Anshul Tyagi
  • 2,076
  • 4
  • 34
  • 65