Ich mag würde, wenn ich die Navigationsleiste Menü zu öffnen, und klicken Sie auf ein bestimmtes Menü, um es anstelle eines Fragments eine Aktivität öffnen kannWie eine Aktivität aus einer Navigationsleiste klicken Sie im Menü zu öffnen, statt Fragment
Hier ist mein Code einige von ihnen auf Fragmente und diejenigen, verbunden sind, die leer sind, würde ich mag sie öffnen eine Aktivität
@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;
}
zum Beispiel auf dem Suchmenü möchte ich es auf eine Aktivität zu verbinden.
Hallo, vielen Dank, aber ich bekomme einen Fehler "kann LogoutIntent nicht beheben" –
Ich habe die Antwort aktualisiert – Inducesmile
Vielen Dank sooo! es hat perfekt funktioniert –