How to set the default tab of multiple swipe views with tabs?

妖精的绣舞 提交于 2019-12-03 13:30:45

The second tab is index 1, all you should need to do is add a setCurrentItem to change the current tab to the correct one after you have setup the page change listener.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_paged);

    ... code omitted ...

    /**
     * on swiping the viewpager make respective tab selected
     **/
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {...}

    // set the default tab to the second tab   
    viewPager.setCurrentItem(1, false);
}

You can use this code to make the desired tab selected

suppose if you want to select the second tab to be default selected tab then

actionBar.setSelectedNavigationItem(1); 

will do the same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!