Je voudrais quand j'ouvre le menu du panneau de navigation et cliquez sur un menu particulier, il peut ouvrir une activité au lieu d'un fragmentComment ouvrir une activité d'un clic de menu Tiroir de navigation au lieu de Fragment
Voici mon code , certains d'entre eux sont liés à des fragments et ceux qui sont vides, je voudrais qu'ils ouvrent une activité
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
//Set the fragment initially
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, new TabFragment()).commit();
} else if (id == R.id.nav_gallery) {
//Set the fragment initially
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, new TabFragment2()).commit();
} else if (id == R.id.nav_nearby) {
//Set the fragment initially
} else if (id == R.id.nav_search) {
//Set the fragment initially
Search fragment = new Search();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_explore) {
//Set the fragment initially
} else if (id == R.id.nav_getverified) {
//Set the fragment initially
GetVerified fragment = new GetVerified();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_getfeatured) {
//Set the fragment initially
GetFeatured fragment = new GetFeatured();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_register) {
//Set the fragment initially
Register fragment = new Register();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_login) {
//Set the fragment initially
Login fragment = new Login();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_report) {
//Set the fragment initially
Report fragment = new Report();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Par exemple dans le menu de recherche Je voudrais lier à une activité.
Salut, merci beaucoup, mais je reçois une erreur "ne peut pas résoudre logoutIntent" –
J'ai mis à jour la réponse – Inducesmile
Merci beaucoup! cela a fonctionné parfaitement –