我希望有不同的标签,你可以在Android市场中轻扫.每个选项卡应使用一个片段并使用一种方法.
这是我的FragmentPagerAdapter类:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment =null;
switch (position) {
case 0:
fragment = new ConnectionFragment();
break;
case 1:
fragment = new DataFragment();
break;
case 2:
fragment = new GraphFragment();
break; }
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}
Run Code Online (Sandbox Code Playgroud)
每个片段类型/选项卡都有三个类:
public static class ConnectionFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number"; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在应用程序中使用Tabs + Swipe,并且想要使用导航类型"固定标签+滑动",ADT在创建活动时为我提供.
Sooo现在ADT吐出了很好的代码,我稍作修改......
我完全理解代码和正在发生的事情......但是我如何教App使用我的三个片段而不是愚蠢的Dummy Frag?:(
我找不到任何处理ADT"导航类型"的教程......
谢谢你的帮助!
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When …Run Code Online (Sandbox Code Playgroud)