Good morning. When I launch my application, the first screen that shows me is the main container of the fragments that I have in the navigation draw. When selecting the items that take me to the different fragments I could not find a way to return to the first screen. I'm sure an attempt is absurd, but I have no idea how to return. Thank you very much for your answers.
public boolean onNavigationItemSelected(MenuItem item) {
FragmentManager fm = getSupportFragmentManager();
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_menu) {
// Handle the camera action
///volver a la pantalla principal
}
else if (id == R.id.nav_pedido) {
// Handle the camera action
fm.beginTransaction().replace(R.id.contenedor,new Pedido()).commit();
} else if (id == R.id.nav_stok) {
fm.beginTransaction().replace(R.id.contenedor,new Stock()).commit();
} else if (id == R.id.nav_deuda) {
fm.beginTransaction().replace(R.id.contenedor,new Deuda()).commit();
} else if (id == R.id.nav_despacho) {
fm.beginTransaction().replace(R.id.contenedor,new Despacho()).commit();
} else if (id == R.id.nav_ventas) {
fm.beginTransaction().replace(R.id.contenedor,new Ventas()).commit();
} else if (id == R.id.nav_ruta) {
fm.beginTransaction().replace(R.id.contenedor,new Ruta()).commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
main xml
<include
layout="@layout/app_bar_vendedor"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_vendedor"
app:menu="@menu/vendedor_drawer" />
xml app bar
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_vendedor" />
xml nav header
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="30sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="Android Studio"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[email protected]"
tools:ignore="HardcodedText" />
xml drawer
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_menu"
android:checkable="false"
android:title="Menu"
tools:ignore="HardcodedText" />
</group>
<item android:title="Transacciones"
tools:ignore="HardcodedText">
<menu>
<item
android:id="@+id/nav_pedido"
android:icon="@drawable/ic_menu_send"
android:title="Ingrese Pedido"
tools:ignore="HardcodedText" />
</menu>
</item>
<item android:title="Consultas"
tools:ignore="HardcodedText">
<menu>
<item
android:id="@+id/nav_stok"
android:icon="@drawable/ic_menu_send"
android:title="Stock" />
<item
android:id="@+id/nav_deuda"
android:icon="@drawable/ic_menu_send"
android:title="Deuda" />
<item
android:id="@+id/nav_despacho"
android:icon="@drawable/ic_menu_send"
android:title="Despacho" />
<item
android:id="@+id/nav_ventas"
android:icon="@drawable/ic_menu_send"
android:title="Avance de Ventas"
tools:ignore="HardcodedText" />
<item
android:id="@+id/nav_ruta"
android:icon="@drawable/ic_menu_send"
android:title="Hoja de Ruta" />
</menu>
</item>