navigation view with tab layout, go to a tab(fragment) by navigation view item on click
<p>I have a tabLayout with 4 four tabs(fragments) attached with the support of FragmentPagerAdapter inside the Activity .</p>

<p>I want to navigate to tabs using the navigation view attached. How to go the tabs when I click on the items in the navigation view.</p>

<p>Then how to remove the current four tabs(which is attached with tablayout) with  new fragment.</p>

<p>To Attach Fragments:</p>

<pre><code>private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new OfferFragment(), "OFFERS");
    adapter.addFragment(new BookedHistoryFragment(), "Booked History");
    adapter.addFragment(new ReviewFragment(), "Reviews");
    adapter.addFragment(new AvailableRoomFragment(), "Available");
    viewPager.setAdapter(adapter);
}
</code></pre>

<p>Sub classAdapter to add the fragments.</p>

<pre><code>class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
    private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}
</code></pre>

<p>Navigation View actions:</p>

<pre><code>mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            mDrawerLayout.closeDrawers();
            if (menuItem.getItemId() == R.id.nav_item_offers) {
                int tabCount= tabLayout.getTabCount();
                // I want to move to other tab.

                Toast.makeText(getApplicationContext(),"First",Toast.LENGTH_SHORT).show();
//                    Intent intent = new Intent(getApplicationContext(), Booking.class);
//                    startActivity(intent);
            }
            else if (menuItem.getItemId() == R.id.nav_item_avail_room) {
                 // Then I want to remove Four tabs and call a new fragment.
                   Toast.makeText(getApplicationContext(),"Second",Toast.LENGTH_SHORT).show();
            }
            return false;
        }

    });
</code></pre>