public void addFragment(Fragment f){ FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction=manager.beginTransaction(); if(fragment!=null){ transaction.hide(fragment); }if(!f.isAdded()){ transaction.add(R.id.frame,f); } transaction.show(f); transaction.commit(); fragment=f; }