0

我已经开始了一个我在 ABS 之后建模的小型应用程序:Fragments -> Tabs and Pager。

在我的应用程序中,我创建了一个如下所示的主要活动:

public class MainActivity extends SherlockFragmentActivity {
TabHost mTabHost;
ViewPager mViewPager;
TabsAdapter mTabsAdapter;
ConfigDBHelper sily_db;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mTabHost = (TabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mViewPager = (ViewPager)findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter(this,mTabHost,mViewPager);

    mTabsAdapter.addTab(mTabHost.newTabSpec("home").setIndicator("Home"),
            MainSupport.CountingFragment.class, null);
    /*
      mTabsAdapter.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
            LoaderCursorSupport.CursorLoaderListFragment.class, null);
      mTabsAdapter.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
            LoaderCustomSupport.AppListFragment.class, null);
      mTabsAdapter.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
            LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
     */

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

代码最终将包含多个选项卡 - 但现在,我只创建了 1 个。

我的 activity_main 布局文件是来自 ABS 的 fragment_tabs_pager.xml 重命名。我的 MainSupport 是 FragmentStackSupport.java 但已重命名。

当我运行我的应用程序时,我看到的不是屏幕顶部的“选项卡”,而是视图中间的唯一一个选项卡 - 涵盖了 fragment_stack.xml 布局和 hello_world.xml 布局。

我怀疑我在某个地方有一个丢失或不正确的指令,但不确定在哪里。特别是当我跳过示例中的 SimpleList.java 模块时。

有任何想法吗?

4

0 回答 0