Source:
<code>private void initializeTabs() { final List<FragmentItemModel> fragmentItems = getFragmentItems(); <START> final TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.appbar).findViewById(R.id.tabs); <END> if (fragmentItems.size() <= 1) { tabLayout.setVisibility(View.GONE); } else { tabLayout.setVisibility(View.VISIBLE); for (FragmentItemModel fragmentItem : fragmentItems) { tabLayout.addTab(createTab(tabLayout, fragmentItem)); } tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { binding.viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } final TabLayout.TabLayoutOnPageChangeListener pageChangeListener = new TabLayout.TabLayoutOnPageChangeListener(tabLayout) { @Override public void onPageSelected(int position) { super.onPageSelected(position); final FragmentItemModel item = fragmentItems.get(position); getActivity().setTitle(item.getTitle()); if (item.getListener() != null) { item.getListener().onFragmentSelected(); } } }; final FragmentItemPagerAdapter adapter = new FragmentItemPagerAdapter(this.getActivity().getSupportFragmentManager(), fragmentItems); binding.viewPager.setAdapter(adapter); binding.viewPager.addOnPageChangeListener(pageChangeListener); binding.viewPager.setOffscreenPageLimit(fragmentItems.size() - 1); binding.viewPager.post(new Runnable() { @Override public void run() { pageChangeListener.onPageSelected(binding.viewPager.getCurrentItem()); } }); }</code><technical_language>getActivity().findViewById(R.id.tabs) work here</technical_language>

Target:
private void initializeTabs() { final List<FragmentItemModel> fragmentItems = getFragmentItems(); final TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tabs); if (fragmentItems.size() <= 1) { tabLayout.setVisibility(View.GONE); } else { tabLayout.setVisibility(View.VISIBLE); for (FragmentItemModel fragmentItem : fragmentItems) { tabLayout.addTab(createTab(tabLayout, fragmentItem)); } tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { binding.viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } final TabLayout.TabLayoutOnPageChangeListener pageChangeListener = new TabLayout.TabLayoutOnPageChangeListener(tabLayout) { @Override public void onPageSelected(int position) { super.onPageSelected(position); final FragmentItemModel item = fragmentItems.get(position); getActivity().setTitle(item.getTitle()); if (item.getListener() != null) { item.getListener().onFragmentSelected(); } } }; final FragmentItemPagerAdapter adapter = new FragmentItemPagerAdapter(this.getActivity().getSupportFragmentManager(), fragmentItems); binding.viewPager.setAdapter(adapter); binding.viewPager.addOnPageChangeListener(pageChangeListener); binding.viewPager.setOffscreenPageLimit(fragmentItems.size() - 1); binding.viewPager.post(new Runnable() { @Override public void run() { pageChangeListener.onPageSelected(binding.viewPager.getCurrentItem()); } }); }