I have two fragments. In the first one there are two buttons and I would like that depending on the button that is clicked, it loads one layout or another in the fragment on the right.
In one of the onclick of a button in the activity I have this:
FrameLayout contenedor = (FrameLayout) findViewById(R.id.fragmento_derecha);
LayoutInflater inflater=LayoutInflater.from(this);
View viewinflado=inflater.inflate(R.layout.boton1,contenedor,true);
On the other button:
FrameLayout contenedor = (FrameLayout) findViewById(R.id.fragmento_derecha);
LayoutInflater inflater=LayoutInflater.from(this);
View viewinflado=inflater.inflate(R.layout.boton2,contenedor,true);
However this does not do what I am looking for. It inflates well one layout or another when clicking a button but it doesn't remove the elements of the previous layout. How could I fix it?
You have to perform a FragmentTransaction , to load a Fragment or another within the FrameLayout :
For example, to load your Fragment containing the layout
R.layout.boton1
:or your Fragment containing the layout
R.layout.boton2
:These would be the classes
miFragmentBoton1()
it inflatesR.layout.boton1
:and
miFragmentBoton2()
that inflatesR.layout.boton2
: