Search code examples
androidandroid-fragmentsandroid-viewpagerswipe-gesture

How to mark the current tab when user swipe on PageViewer


I'm having a ViewPager that contains 3 views. When the user click over a Tab, the view chages correctly and the tab bottom border is mark as selected. The situation is that when the user swipe(left or right) the view changes as expected but the tab does not get marked as selected. I need to mark the tab even if the user swipe.

Is there anyway that can force the tab to get selected when user swipe between views?

If you need any code let me know.


Solution

  • I think you must implement a OnTabChangeListener in your code. Here I show you the way I'm doing it.

    implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener
    

    And implement method:

    public void onPageSelected(int position) {
                //==== set tab
                mTabHost.setCurrentTab(position);
    }