I have this GUI to select some Fragments I have in the application. When I select the "Empleados" option, a ListView inside a Fragment appears like this:
<activity
android:name=".actividades.admin.InicioAdmin"
android:theme="@style/AppTheme">
</activity>
This is the switch where I inicialize the Fragment.
Fragment fragment = null;
switch (posicion) {
case 0:
fragment = new HomeFragment();
break;
case 1:
fragment = new EmpleadoFragment();
break;
case 3:
UsuarioFunciones.cerrarSesion(context);
Intent inicio = new Intent(getApplicationContext(), Login.class);
inicio.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(inicio);
finish();
Toast.makeText(context,"Sesión finalizada",Toast.LENGTH_LONG).show();
break;
default:
break;
}
if (fragment != null) {
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
fragment).commit();
listView.setItemChecked(posicion, true);
listView.setSelection(posicion);
setTitle(navMenuTitulos[posicion]);
drawerLayout.closeDrawer(listView);
}
EmpleadoFragment.java (extends Fragment)
When selecting an employee, it loads a ActionBarActivity where you can do some functions for that employee.
My question is how can i run the navigation button back to reopen the Fragment where is the ListView?.
When I press the physical "Back" button the ListView is reopened, but with the App Icon not working.
AndroidManifest.xml for the ActionBarActivity above (DetalleEmpleado.java):
<activity
android:name=".actividades.admin.DetalleEmpleado"
android:label="@string/actividad_detalle_empleado"
android:theme="@style/AppTheme"
android:parentActivityName=".SampleParentActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".SampleParentActivity"/>
</activity>
You must put the code to return in the onOptionsItemSelected of your ActionBarActivity. Here you can find more information.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//Close current activity
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments