I have a Activity
that has two NavigationDrawer
s one on each side. I wanted to clean this up and pull both menus out into their own xml file and use include to reference them in the main xml. This works for the left drawer but not the Right.
<include
android:id="@+id/friendsInclude"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/friend_feed"
android:layout_gravity="start"/>
<!-- Notification Feed -->
<include
android:id="@+id/notificationInclude"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/notification_feed"
android:layout_gravity="end" />
Both have their own XML with the root layout being a Relative layout. They look like this..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:id="@+id/friendsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#F5F5F5">
and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:id="@+id/notificationsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#F5F5F5" >
In our main activity we get a null pointer when trying to open the right drawer via the action bar.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
if(item.getItemId() == R.id.notifications) {
if(drawerLayout.isDrawerVisible(notificationsLayout)) { //nullpointer
drawerLayout.closeDrawer(notificationsLayout);
} else {
drawerLayout.openDrawer(notificationsLayout);
drawerLayout.closeDrawer(friendsLayout);
}
}
if(item.getItemId() == R.id.refresh) {
new AsyncMainFeed(this).execute("");
new AsyncFriendFeed().execute("");
new AsyncNotificationFeed(this).execute("");
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
And I declare my layouts like this
friendsLayout = (RelativeLayout)findViewById(R.id.friendsLayout);
notificationsLayout = (RelativeLayout)findViewById(R.id.notificationsLayout);
I'm kinda stumped on where this is coming from any ideas?