das ist meine AktivitätviewPager reagiert nicht auf die Registerkarte klicken
public class MainActivity extends AppCompatActivity {
private ViewPager viewPager;
private TabLayout tablayout;
private int[] tableIcons = {android.R.drawable.ic_menu_camera,
android.R.drawable.ic_menu_add, android.R.drawable.ic_media_next};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
tablayout = (TabLayout) findViewById(R.id.tab);
setUpwithviewpager(viewPager);
tablayout.setupWithViewPager(viewPager);
tablayout.getTabAt(0).setIcon(tableIcons[0]);
tablayout.getTabAt(1).setIcon(tableIcons[1]);
tablayout.getTabAt(2).setIcon(tableIcons[2]);
tablayout.setTabMode(TabLayout.MODE_FIXED);
}
public void setUpwithviewpager(ViewPager viewpager) {
ViewPageradapter adapter = new ViewPageradapter(getSupportFragmentManager());
adapter.addFragment(OneFragment.newInstance("1"), "one");
adapter.addFragment(TwoFragment.newInstance("2"), "two");
adapter.addFragment(ThreeFragment.newInstance("3"), "three");
viewpager.setAdapter(adapter);
}
}
dies das Layout XML-Datei
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"></android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager></android.support.design.widget.CoordinatorLayout>
Mein tablayout reagiert nicht, wenn ich die viewpager ändern, und die ViewPager reagiert auch nicht, wenn ich auf die Tabs klicke. Ich weiß nicht warum, ich kann keine Lösung finden, um dieses Problem zu lösen.