I'm building an app on Android and it will have among the various activities a fragment for user profile.
The problem is that, from the selection of the profile, you need to go from the main activity to the fragment. But I'm having trouble with the transaction.
I do not know if I'm using it the wrong way or something, I'll leave the activity code:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_Cadastrar)
{
Intent cadastrar = new Intent(NossaVozActivity.this, CadastroActivity.class);
startActivity(cadastrar);
}
if (id == R.id.nav_Login)
{
Intent login = new Intent(NossaVozActivity.this, LoginActivity.class);
startActivity(login);
}
else if (id == R.id.nav_Denuncia)
{
Intent denuncia = new Intent(NossaVozActivity.this, DenunciaActivity.class);
startActivity(denuncia);
}
else if(id == R.id.nav_perfil)
{
Intent perfil = new Intent(NossaVozActivity.this,PerfilFragment.class);
startActivity(perfil);
}
else if (id == R.id.nav_Sair)
{
{
Intent fim = new Intent(NossaVozActivity.this, FimActivity.class);
startActivity(fim);}
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}