Android:TabHost 如何:在菜单按钮上的现有选项卡中设置新内容?

发布于 2024-09-02 11:57:06 字数 479 浏览 10 评论 0原文

我最近开始 Android 编程,正在开发我的第一个程序,该程序显示历史文本文档,通过 TabHost 按选项卡进行分区。我将我的程序限制为一项活动,并且仅在 TabSpec 中使用 setContent 在不同的 XML 视图之间切换。

该文档包含未经编辑和更正的文本版本,我已为其构建了文本视图以适应这些版本。我想实现标准菜单,使其具有“查看更正”和“查看原始”按钮,并切换已更改的选项卡的内容(不更改选项卡或其指示器)。

我读过 TabHost API,并且无法使用 TabSpec 的 setContent() 编辑现有选项卡内容;并且 AFAIK TabWidget 仅影响实际的选项卡,而不影响按下它们时显示的内容。

我考虑过创建一个新类,它扩展了 TabHost 和 super() 所有原始方法,同时还包含一个更新 mTab​​Spec 列表的方法。

我的问题是,如何更新特定选项卡的frameLayout视图以显示我指定的内容?

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 altering 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-09-09 11:57:06

我会向你指出两个可能的方向。因为有点晚了,我不会详细说明,如果你明天没有答案,我会给你更多的:
您可以使用 ViewSwitcher 类,当您有 2 个视图需要处理时,这对于这种事情来说非常有用。您可以找到 这里有一个很好的教程。或者,您可以创建两个视图,一个叠加在另一个视图上,当您单击按钮从原始视图转到更正后,只需将属性可见性从“可见”更改为“消失”,而另一个视图则相反。但它的编码不如以前的方式好,尽管编码更容易(很高兴测试您的观点)

希望有所帮助,

Sephy

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文