Your Activity, is implementing NavigationView.OnNavigationItemSelectedListener
, right?
Then you will have a method like this:
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.consultas_abertas) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, ConsultaAbertasFragment, name)
.commit();
}
//Resto do código
drawer.closeDrawer(GravityCompat.START);
return true;
}
The system will verify which menu id was clicked, and will call the Fragment corresponding to it, and the system itself will take care of selecting the Fragment that was called.
The XML of your Menu, should look something like this:
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/consultas_abertas"
android:title="Consultas Abertas" />
//Resto do código
</group>
</menu>
And finally, in the XML of your Activity, you should have the Framelayout where the Fragments will be loaded, referring to this id R.id.container
, example:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>
You’re already carrying this fragment
Consultas Abertas
?– Leonardo Dias
So, I’m novice in android, and put me to do this project, so I don’t know much how to use the navigation Activity @Leonardodias
– Matheus Rohwedder