I have a navigation drawer with swipe views and tab navigation.
My problem is that when navigation drawer is pulled tabs are gone and when i swipe project stops unexpectedly.
Below is the logcat
here is where studio points the error.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);//error here
}
});
05-05 12:00:05.590 19095-19095/com.dot.shreyans.drwaer E/InputEventReceiver﹕ Exception dispatching input event. 05-05 12:00:05.590 19095-19095/com.dot.shreyans.drwaer E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback 05-05 12:00:08.100 19095-19095/com.dot.shreyans.drwaer E/MessageQueue-JNI﹕ java.lang.IllegalStateException: setSelectedNavigationIndex not valid for current navigation mode at android.support.v7.internal.app.WindowDecorActionBar.setSelectedNavigationItem(WindowDecorActionBar.java:420) at com.dot.shreyans.drwaer.MainActivity2Activity$1.onPageSelected(MainActivity2Activity.java:69) at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:572) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:556) at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:2020) at android.view.View.dispatchTouchEvent(View.java:7248) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405) at android.app.Activity.dispatchTouchEvent(Activity.java:2410) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901) at android.view.View.dispatchPointerEvent(View.java:7428) at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3223) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3167) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4295) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4274) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4366) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:125) at android.os.Looper.loop(Looper.java:124) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) 05-05 12:00:08.100 19095-19095/com.dot.shreyans.drwaer D/AndroidRuntime﹕ Shutting down VM 05-05 12:00:08.100 19095-19095/com.dot.shreyans.drwaer W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x412af930) 05-05 12:00:08.140 19095-19095/com.dot.shreyans.drwaer E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalStateException: setSelectedNavigationIndex not valid for current navigation mode at android.support.v7.internal.app.WindowDecorActionBar.setSelectedNavigationItem(WindowDecorActionBar.java:420) at com.dot.shreyans.drwaer.MainActivity2Activity$1.onPageSelected(MainActivity2Activity.java:69) at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:572) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:556) at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:2020) at android.view.View.dispatchTouchEvent(View.java:7248) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405) at android.app.Activity.dispatchTouchEvent(Activity.java:2410) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901) at android.view.View.dispatchPointerEvent(View.java:7428) at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3223) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3167) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4295) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4274) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4366) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:125) at android.os.Looper.loop(Looper.java:124) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)
Thanks,
here is xml of activity
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout_test"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity2Activity">
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.dot.shreyans.drwaer.MainActivity2Activity" /></FrameLayout>
<fragment android:id="@+id/navigation_drawer_test"
android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.dot.shreyans.drwaer.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
here is the listener
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
};