Home > Software design >  Fragment to Fragment
Fragment to Fragment

Time:08-07

I want to pass the fragment to fragment but if i pass the new fragment i show old fragment widgets why?

enter image description here

this code is in MessageFragment I want to go from MessageFragment to HomeFragment but i can but i show message fragment edittext, imageview etc. why?

 public void goMessagesToHome(){
    HomeFragment homeFragment = new HomeFragment();
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.fragmentMessage, homeFragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

CodePudding user response:

SOLVED

ı have to do that i have navhostfragment so i write that.

  public void goMessagesToHome(){
    HomeFragment homeFragment = new HomeFragment();
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.navHostFragment, homeFragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

fragmentTransaction.replace(R.id.navHostFragment, homeFragment);

this place is important

  • Related