我已经有了可滑动的标签,但我也希望能够看到这些视图。
怎么做?有没有教程?
这是从FragmentStatePagerAdapter
扩展的类:
public class TabPagerAdapter extends FragmentStatePagerAdapter实现了SimpleGestureListener {
private SimpleGestureFilter detector;
public TabPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
detector = new SimpleGestureFilter(this, this);
Log.d("TabPagerAdapter", "TabPagerAdapter " + detector);
}
@Override
public Fragment getItem(int auswahl) {
switch (auswahl) {
case 0:
return new Text();
}
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
// ANzahl der Tabs, die mit Funktionen belegt sind
// muss richtig sein, damit was angezeigt wird, oder nicht abstürzt
return 1;
}
@Override
public void onSwipe(int direction) {
String str = "";
Log.d("str", "str " + str);
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
str = "Swipe Right";
break;
case SimpleGestureFilter.SWIPE_LEFT:
str = "Swipe Left";
break;
case SimpleGestureFilter.SWIPE_DOWN:
str = "Swipe Down";
break;
case SimpleGestureFilter.SWIPE_UP:
str = "Swipe Up";
break;
}
// Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
Log.d("str", "str " + str);
}
@Override
public void onDoubleTap() {
// TODO Auto-generated method stub
}
这是我的FragmentActivity
:
public class OpenprojectAlternative extends FragmentActivity implements ActionBar.TabListener {
ViewPager viewPager;
TabPagerAdapter TabAdapter;
ActionBar actionBar;
private String[] tabs = { "Texte", "Bilder + Videos", "Karte", "Sound", "Zeichnungen"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.openprojecttabs);
TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(TabAdapter);
actionBar = getActionBar();
// Enable Tabs on Action Bar
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
Log.d("onPageSelected", "onPageSelected " + position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onTabReselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(android.app.ActionBar.Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
非常感谢