I created my own TabLayout menu (from an empty Activity) with a modified SectionPagerAdapter from a TabActivity project. I only changed the getItem() method and removed the page title method.
public Fragment getItem(int position) {
switch (position)
{
case 0:
HomeActivity home = new HomeActivity();
return home;
case 1:
PayActivity pay = new PayActivity();
return pay;
case 2:
VideoActivity video = new VideoActivity();
return video;
case 3:
BillActivity bill = new BillActivity();
return bill;
default:
return null;
}
}
}
And after the execution of
TabLayout tabToolbar = (TabLayout) findViewById(R.id.tabToolbar);
ViewPager viewPager = (ViewPager) findViewById(R.id.container);
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mSectionsPagerAdapter);
tabToolbar.setupWithViewPager(viewPager);
my App has been stopped.
If I comment
tabToolbar.setupWithViewPager(viewPager);
than my menu doesn't work but I can swipe between my fragments within the ViewPager.
I want to swipe with my menu button and by swipping with my mousecursor as well.
If you need some more information or resources please let me know.
Edit:
The error log shows:
09-08 06:19:05.822 4207-4207/com.example.fdai3744.t_online20 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fdai3744.t_online20, PID: 4207
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fdai3744.t_online20/com.example.fdai3744.t_online20.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
at com.example.fdai3744.t_online20.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2nd edit:
I found out that my adapter has no "public CharSequence getPageTitle(int position)" method.