it would be nice, if i could swipe between the tabs i had in my actionbar.
I've followed these tutorial: http://developer.android.com/training/implementing-navigation/lateral.html but it wont work. :( I cannot swipe with a gesture between the tabs.
Here is my main activity:
public class Hauptmenue_extended extends ActionBarActivity implements
android.content.DialogInterface.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hauptmenue_extended);
try {
mPullToRefreshAttacher = PullToRefreshAttacher.get(this);
actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mAdapter);
Tab tabB = actionBar.newTab();
tabB.setText("Home");
tabB.setIcon(R.drawable.icon_home);
tabB.setTabListener(new TabListener<Startmenue_activity>(this,
"Start", Startmenue_activity.class, this.mViewPager));
actionBar.addTab(tabB);
Tab tabA = actionBar.newTab();
tabA.setText("");
tabA.setIcon(R.drawable.icon_nachrichten_sel);
tabA.setTabListener(new TabListener<Nachrichten_activity>(this,
"Nachrichten", Nachrichten_activity.class, this.mViewPager));
actionBar.addTab(tabA);
Tab tabC = actionBar.newTab();
tabC.setText("");
tabC.setIcon(R.drawable.icon_favoriten);
tabC.setTabListener(new TabListener<Favoriten_activity>(this,
"Favoriten", Favoriten_activity.class, this.mViewPager));
actionBar.addTab(tabC);
this.conEinst = new conEinstellungen(getBaseContext());
} catch (Exception ex) {
ex.printStackTrace();
// HelperClassAlertDialog.zeigeInfoDialog(this, "Error...",
}
}
public class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
public Fragment getItem(int index) {
switch (index) {
case 0:
// Top Rated fragment activity
return new Startmenue_activity();
case 1:
// Games fragment activity
return new Nachrichten_activity();
case 2:
// Movies fragment activity
return new Favoriten_activity();
}
return null;
}
public int getCount() {
// get item count - equal to number of tabs
return 3;
}
}
And this is the XML:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.PagerTabStrip android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" /> </android.support.v4.view.ViewPager>
This works perfectly, you will swipe between tabs:
MainActivity
:activity_main
:tab1.xml
:tab2.xml
:tab3.xml
:Have you ever seen this this one. It will help you for creating Tabs with ActionBar