Answer the question
In order to leave comments, you need to log in
How to implement .OnDrawerItemClickListener across fragments?
Please help implement
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {
switch (drawerItem.getIdentifier()) {
case 1:
break;
}
}
}).build();
TabLayout tabLayout = (TabLayout)findViewById(R.id.tabLayout);
TabFragmentAdapterPlants adapterPlants = new TabFragmentAdapterPlants(getSupportFragmentManager());
viewPager.setAdapter(adapterPlants);
tabLayout.setupWithViewPager(viewPager);
Answer the question
In order to leave comments, you need to log in
This is how everything works, but I'm wondering if it will be correct and not affect performance?
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {
TabLayout tabLayout = (TabLayout)findViewById(R.id.tabLayout);
switch (drawerItem.getIdentifier()){
case 2:
TabFragmentAdapterPlants adapterPlants = new TabFragmentAdapterPlants(getSupportFragmentManager());
viewPager.setAdapter(adapterPlants);
tabLayout.setupWithViewPager(viewPager);
break;
case 1:
TabFragmentAdapter adapter = new TabFragmentAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
break;
}
}
})
.build();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question