开发者

Android: TabHost How To: set new content in existing tabs upon menu button?

开发者 https://www.devze.com 2022-12-31 06:43 出处:网络
I recently started Android programming and was working on my first program which displays a historic text document, sectioned by tabs via TabHost.I have limited my program to one activity and merely u

I recently started Android programming and was working on my first program which displays a historic text document, sectioned by tabs via TabHost. I have limited my program to one activity and merely used setContent in my TabSpec's to switch between different XML views.

The document has both unedited and corrected versions of the text for which I have built text views to accommodate. I wanted to implement the standard menu to have buttons to "view corrected" and "view original" and switch the content of the tabs which have changes (without a开发者_如何学运维ltering the tabs or their indicators).

I've read on the TabHost API and there is no way to edit existing tab content with setContent() of TabSpec; and AFAIK TabWidget only affects the actual tabs, not the content that is displayed upon pressing them.

I've thought about creating a new class which extended TabHost and super() all of the original methods, while including one more which updated the mTabSpec list.

My question would be, how would I update the frameLayout view of a specific tab to display content I specify?


I would point you in 2 possible directions.As it's a bit late I won't go into details, and If you have no answer tomorrow, I'll give you some more: You can use the ViewSwitcher class, that is really great for this kind of thing when you have 2 views to deal with.You can find a good tutorial here. Or you can create the 2 Views one on top of the other and when you click your button to go from original to corrected just change the attribute visibility from VISIBLE to GONE and the opposite for the other view. But it's less nice coding than the previous way, though much easier to code (nice to test your views)

Hope that helps,

Sephy

0

精彩评论

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