There is a created NavigationDrawer , connected to it tabs. It turns out that the first Item with tabs (fragments) in the Drover works correctly, and already the 2nd one displays the same information ( TextView ), the one that is in the first Item and in its tabs.
Tell me how to fix it, in the code, if possible?

enter image description here enter image description here

Here, in fact, the code itself of the 2nd item and its tabs in activation:

MainActivity :

 public class MainActivity extends AppCompatActivity { private static final int LAYOUT = R.layout.activity_main; private Drawer.Result drawerMenu; private ViewPager viewPager; private Toolbar toolbar; private TabLayout tabLayout; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.myTheme2); super.onCreate(savedInstanceState); setContentView(LAYOUT); initTabs(); // Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅ΠΌ Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); if (toolbar !=null) { setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } initializeNavigationDrawer(toolbar); } private void initTabs() { viewPager = (ViewPager) findViewById(R.id.viewPager); // Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅ΠΌ TabLayout tabLayout = (TabLayout)findViewById(R.id.tabLayout); TabFragmentFish adapter = new TabFragmentFish(getSupportFragmentManager()); viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); } @Override public void onBackPressed() { if (drawerMenu != null && drawerMenu.isDrawerOpen()) { drawerMenu.closeDrawer(); } else { super.onBackPressed(); } } //Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ Π”Ρ€Π°Π²Π΅Ρ€Π° private void initializeNavigationDrawer(Toolbar toolbar) { drawerMenu = new Drawer() .withActivity(this) .withToolbar(toolbar) .withActionBarDrawerToggle(true) .withHeader(R.layout.drawer_header) //Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π˜Ρ‚Π΅ΠΌΠΎΠ² Π² ΡˆΡ‚ΠΎΡ€ΠΊΡƒ .addDrawerItems( new PrimaryDrawerItem() .withName(R.id.aqua_fish) .withIdentifier(1) .withIcon(FontAwesome.Icon.faw_circle), new PrimaryDrawerItem() .withName(R.id.aqua_plant) .withIdentifier(2) .withIcon(FontAwesome.Icon.faw_leaf), new PrimaryDrawerItem() .withName(R.id.aqua_water) .withIdentifier(3) .withIcon(FontAwesome.Icon.faw_tint), new PrimaryDrawerItem() .withName(R.id.aqua_lighting) .withIdentifier(4) .withIcon(FontAwesome.Icon.faw_lightbulb_o), new PrimaryDrawerItem() .withName(R.id.aqua_co2) .withIdentifier(5) .withIcon(FontAwesome.Icon.faw_circle), new PrimaryDrawerItem() .withName(R.id.aqua_filtration) .withIdentifier(6) .withIcon(FontAwesome.Icon.faw_filter), //--------------------------------------------- Secondary new DividerDrawerItem(), new SecondaryDrawerItem() .withName(R.id.about) .withIdentifier(7), new SecondaryDrawerItem() .withIdentifier(8) .withName(R.id.exit)) //Π Π΅Π°Π»ΠΈΠ·ΡƒΠ΅ΠΌ ΠΊΠ»ΠΈΠΊ ΠΏΠΎ айтэмам .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { switch (drawerItem.getIdentifier()){ case 1: TabFragmentFish adapter = new TabFragmentFish(getSupportFragmentManager()); viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); break; case 2: TabFragmentAdapterPlants adapterPlants = new TabFragmentAdapterPlants(getSupportFragmentManager()); viewPager.setAdapter(adapterPlants); tabLayout.setupWithViewPager(viewPager); break; //Мини окошко "Об Π°Π²Ρ‚ΠΎΡ€Π΅ с Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠ΅ΠΌ ОК" case 7: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.AppCompatAlertDialogStyle); builder .setTitle("Об Π°Π²Ρ‚ΠΎΡ€Π΅") .setMessage("Автор:АртСм ΠœΠΈΡˆΡƒΡ€ΠΎΠ²ΡΠΊΠΈΠΉ"+"\n\nEmail: artm.mishurovskiy@gmail.com") .setCancelable(false) .setNegativeButton("Ок", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.cancel(); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); break; //Π’Ρ‹Ρ…ΠΎΠ΄ ΠΈΠ· ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ case 8: finish(); break; } } }) .build(); } } 

The adapter itself and tabs are created in it:

 public class TabFragmentAdapterPlants extends FragmentPagerAdapter { //Create massive private String[] tabs; private FragmentTransaction fTrans; public TabFragmentAdapterPlants(FragmentManager fm) { super(fm); //Create tabs tabs= new String[] { "РастСния", "Π‘ΠΎΠ»Π΅Π·Π½ΠΈ растСний", "Водоросли" }; } //ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ Π’Π°Π±ΠΎΠ² Ρ‡Ρ‚ΠΎ Π± ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ ΠΈΡ… Π² свитч @Override public CharSequence getPageTitle(int position) { return tabs[position]; } //ΠŸΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΌΠ΅ΠΆΠ΄Ρƒ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Π°ΠΌΠΈ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ 0,1,2 @Override public Fragment getItem(int position) { switch (position){ case 0: return FragmentPlants.getInstance(); case 1: return FragmentsPlantsDisease.getInstance(); case 2: return FragmentPlantsAlgae.getInstance(); } return null; } //табс Π² ΡˆΠΈΡ€ΠΈΠ½Ρƒ !! @Override public int getCount() { return tabs.length; } } 

Fragment to which the adapter switches:

 public class FragmentPlants extends Fragment { private static final int LAYOUT = R.layout.fragments_plants2; private View view; public static FragmentPlants getInstance(){ Bundle args = new Bundle(); FragmentPlants fragmentPlants = new FragmentPlants(); fragmentPlants.setArguments(args); return fragmentPlants; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(LAYOUT, container, false); return view; } } 
  • You need to implement the required number of fragments, each of which has its own ViewPager , and not one ViewPager in the ViewPager . Then, from the Drover, call these fragments, which contain their own pager. In the active container only to display the fragment and all. See this example - pavlofff

1 answer 1

Or you have the same layout for the fragments, or the viewPager does not update the adapter. In the second case, this answer can help.