Prueba de fragments en android, ejemplo sencillo donde con 2 botones cambiamos el fragment
Se hace prueba con fragments en android
Usando el siguiente método conseguimos que se cambie el contenido del fragment
public void selecFrag(View view) {
// Según el boton creamos un fragmento u otro
Fragment frag;
if(view == findViewById(R.id.btn1)){
frag = new Fragment1();
}else{
frag = new Fragment2();
}
// Usamos el gestor de fragmentos para los cambios
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.replace(R.id.fragment, frag);
trans.commit();
}