Call screen with fragment

1

I created a screen with a list view based on the native fragment of android studio, but I did not find a solution to "call" this screen from a button.

 public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {

    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }
    
asked by anonymous 05.07.2017 / 21:10

1 answer

1

You need to use FragmentManager, for example:

 FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, NomeDoFragmentAqui, "titulo do fragment")
                .commit();

And in your layout, you need to have FrameLayout, which will be where the Fragment will be placed, eg:

<FrameLayout
     android:id="@+id/container"
     android:layout_width="match_parent"
     android:layout_height="match_parent" />
    
05.07.2017 / 21:14