开发者

Android Tabbed Layout - how to have sub-section links?

开发者 https://www.devze.com 2023-03-24 13:56 出处:网络
I\'m trying to c开发者_Python百科reate an app with tabs for the main menu with sections Main, Adult and Paeds and buttons within each tab that link to other content . The layout is like this:

I'm trying to c开发者_Python百科reate an app with tabs for the main menu with sections Main, Adult and Paeds and buttons within each tab that link to other content . The layout is like this:

  • Main
    • General info
  • Adult
    • Section 1 (button)
    • Section 2 (button)
  • Paeds
    • Section 1 (button)
    • Section 2 (button)

Here is an image from the app so far:

Android Tabbed Layout - how to have sub-section links?

I can get this working and also set up the buttons so that I can go to the content of the subsections, but without the tabs staying at the top. So the app works fine, to a point.

What I really want is for the tabs to stay there. This would allow for much easier navigation than having to press the back button if you wanted to go between the 3 main sections.

Does anyone have any idea how to do this?


Prior to Honeycomb, you'd accomplish something like this by putting each tab's set of activities within an ActivityGroup (see this SO post or this one). However, this has been deprecated, and it's recommended to use the Fragment class to accomplish something like this. Of course, if you're ok with using deprecated classes, the SO post above should do the trick.

Basically, you'll need to create an activity for each of the tabs (you might try extending FragmentActivity). Then, within each of these activities, their content will be represented as Fragments. It's up to you to do the management properly for them. Here's some sample code from Google on the TabActivity class that I used to get started: http://developer.android.com/reference/android/app/TabActivity.html

Here's another example from google on implementing Fragments & tabs: http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html

This is a good place to start if you're trying to learn about Fragments.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号