0

I have been using a TabLayout till now to navigate between different tabs in my application. I need to remove the Tablayout and navigate between the tabs using menu items in the toolbar.

This is the code I have been using.

viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });
}

What code should I add in the OnOptionsItemSelected() section?.

1 Answer 1

1

suppose you have to navigate to position "p" then,

viewPager.setCurrentItem(p);

that's it.

And no need to add any listener.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.