Answer the question
In order to leave comments, you need to log in
Why does not show the desired fragment when selecting the menu item nav drawer android?
I have two fragments in the program, each of which is responsible for one type of message - incoming or outgoing. There is an adapter that implements the selection of these fragments. And I want to make it so that when I select a menu item, I see a certain fragment. Here is my adapter:
public class PagerAdapter extends FragmentStatePagerAdapter {
private int mNoOfTabs;
public PagerAdapter(FragmentManager fm) {
super(fm);
//this.mNoOfTabs = NumberOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position)
{
case 0:
return new Received();
case 1:
return new Sent();
/* default:
return new Received();*/
}
return new Sent();
}
@Override
public int getCount() {
return mNoOfTabs;
}
}
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
fragmentManager = getSupportFragmentManager();
/* mAdapter = new PagerAdapter(getSupportFragmentManager());
mPager = findViewById(R.id.frame);*/
ft = fragmentManager.beginTransaction();
if (id == R.id.received) {
ft.replace(R.id.frame, new Received());
} else if (id == R.id.sended) {
ft.replace(R.id.frame, new Sent());
}
ft.commit();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
mAdapter = new PagerAdapter(getSupportFragmentManager());
mPager = findViewById(R.id.frame);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question