50% Off/-

50% Off/-

Php

50% Off/-

50% Off/-

Web

50% Off/-

50% Off/-

Fragment re-created on bottom navigation view item selected Solution

21-01-2019
private void changeFragmentForBottomNavigationView(Bundle savedInstanceState, Fragment fragment) {
    
    // Check that the activity is using the layout version with
    // the fragment_container FrameLayout
    if (findViewById(R.id.fragment_container) != null) {
        
        // However, if we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        if (savedInstanceState != null) {
            return;
        }
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        
        Fragment curFrag = getSupportFragmentManager().getPrimaryNavigationFragment();
        if (curFrag != null) {
            fragmentTransaction.detach(curFrag);
        }
        
        Fragment fragmentFromManager = getSupportFragmentManager().findFragmentByTag("BOTTOM_FRAGMENT");
        if (fragmentFromManager == null) {
            fragmentFromManager = fragment;
            fragmentTransaction.add(R.id.fragment_container, fragmentFromManager, "BOTTOM_FRAGMENT");
        } else {
            fragmentTransaction.attach(fragmentFromManager);
        }
        
        fragmentTransaction.setPrimaryNavigationFragment(fragmentFromManager);
        fragmentTransaction.setReorderingAllowed(true);
        fragmentTransaction.commitNowAllowingStateLoss(); 
    }
    
}

© 2019 Tüm Hakları Saklıdır. Codesenior.COM