質問

I have used a FragmentTabHost to create four tabs with corresponding fragments. The tabs work, however, now that I want to add dynamic UI (such as a TextView that displays the current date, and interactive buttons) I am not sure how to proceed. I have found that trying to add it to the fragments is incorrect and adding it to the main also causes error. There must be some way to do this, but my lack of android experience has me lost. So, is there a way to add dynamic UI to fragments?

役に立ちましたか?

解決

I assume you have created FragmentTabHost like in in the documentation.

You have now to define each fragment which will be in each tab. For example, in the doc, there are 4 fragments referenced :

    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
            FragmentStackSupport.CountingFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
            LoaderCursorSupport.CursorLoaderListFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
            LoaderCustomSupport.AppListFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
            LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
  • FragmentStackSupport.CountingFragment
  • LoaderCursorSupport.CursorLoaderListFragment
  • LoaderCustomSupport.AppListFragment
  • LoaderThrottleSupport.ThrottledLoaderListFragment

Those are only examples of Fragment implementation (you can found their implementation in the doc).

Then, it depends what you'd like to have in each tab (display a list, a few buttons,..). You can have a look at the training lesson Building a Dynamic UI with Fragments or the documentation about Fragment.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top