Frage

I have an Activity that shows two Fragments side by side. FragmentB has to be invisible until a button is clicked in FragmentA. Is there a way to make a fragment invisible? (Both fragments are still there but there is a blank space until FragmentB becomes visible)

What do I have to do and in what file should I make changes? Can I have an example please?

The files: MainActivity.java, FragmentA.java , FragmentB.java, activity_main.xml, fraga.xml, fragb.xml

War es hilfreich?

Lösung

Fill the place of fragment B with an empty FrameLayout. On button click, add the fragment B to that Framelayout (Create it)

public void atButtonClicked()
{
    FragmentB b = new FragmentB();

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.add(R.id.fragmeLayout, b);
    transaction.commit();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top