I want when a button from the navigation menu is clicked to start a new activity. With the current code nothing happens when the button is clicked. I'm new to Android so plese don't get mad if I don't understand your code and ask some questions.
Here is my navigation_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/nav_account"
android:title="Home"
android:icon="@mipmap/ic_home_black_24dp">
</item>
<item android:id="@+id/nav_delete"
android:title="Delete Boards"
android:icon="@mipmap/ic_close_black_24dp">
</item>
<item android:id="@+id/nav_settings"
android:title="Settings"
android:icon="@mipmap/ic_settings_black_24dp">
</item>
And here is my mainActivity.java code for the drawer:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)){
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.nav_delete) {
//call new activity
}
}
return super.onOptionsItemSelected(item);
}
}
MainActivity.xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.studios.cookie.chanomatic.MainActivity"
android:id="@+id/drawerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.02"
android:text="Boards"
android:textAlignment="center"
android:textColor="@android:color/black" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id = "@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>