How to define a unique ID to a fragment in android studio?

1

I try to call a fragment for my Navegation Drawer but it does not have an ID and if I try to put it in the XML file it marks me error

FragmentManager manager=getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.aquiMarcaError,new Padre_Scrolling()).commit();
    
asked by Braulio 20.06.2018 в 01:52
source

1 answer

1

In your XML you should have something like that, FrameLayout that will be the "container" where the change of fragments will be made:

....

  <FrameLayout
        android:id="@+id/id_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

....

In your java file:

FragmentManager manager=getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.id_frame,new Padre_Scrolling()).commit();       

This only works if you are adding a single Fragment as is your case.

    
answered by 20.06.2018 в 16:06