Hello, I am facing problem about android fragment. I am using android 
navigation pane view created by android studio template. I added some 
fragments in it, while switching an fragment by 
FragmentManager.getFragmentManager().replace() method, the components of 
previous fragment are visible on the next fragment i switched to. How do i 
remove such components completely after switching fragment.



public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.nav_profile) {
        ProfileFragment profileFragment=new ProfileFragment();
        Bundle bundle=new Bundle();
        bundle.putString("user_name",user_name);
        profileFragment.setArguments(bundle);
        FragmentManager fragmentManager=getSupportFragmentManager();
        fragmentManager.beginTransaction()
                
.replace(R.id.content_home_relative_layout,profileFragment).commit();
    } else if (id == R.id.nav_person) {
        PersonSearchFragment personSearchFragment=new PersonSearchFragment();
        Bundle bundle=new Bundle();
        bundle.putString("user_name",user_name);
        personSearchFragment.setArguments(bundle);
        FragmentManager fragmentManager=getSupportFragmentManager();
        fragmentManager.beginTransaction()
                
.replace(R.id.content_home_relative_layout,personSearchFragment).commit();
    } else if (id == R.id.nav_settings) {

    } else if (id == R.id.nav_contact) {

    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/ca069b0a-9935-4160-abf2-d45c7668d46a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to