A
A
Artem Mishurovsky2017-02-22 01:36:35
Java
Artem Mishurovsky, 2017-02-22 01:36:35

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();

I want that in case 1, by clicking on the 1-you item, this fragment pops up:
TabLayout tabLayout = (TabLayout)findViewById(R.id.tabLayout);
TabFragmentAdapterPlants adapterPlants = new TabFragmentAdapterPlants(getSupportFragmentManager());
viewPager.setAdapter(adapterPlants);
tabLayout.setupWithViewPager(viewPager);

I tried to insert all these lines into case 1, but it seems to me that it would not be right, you can put it in onCreate and just insert fragment.replace().commit();
Please help make this happen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Mishurovsky, 2017-02-22
@Innerbloom

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 question

Ask a Question

731 491 924 answers to any question