强制 Tabhost 启动 Activity(刷新)

发布于 2024-09-29 13:25:24 字数 246 浏览 0 评论 0原文

简单来说。从 TabActivity 的上下文菜单中,如何启动执行当前选项卡的意图?我正在尝试强制刷新。

所有选项卡都会启动显示人名子集的活动。在一个列表中,您可以调用一项编辑活动,该活动允许您将名称与 TabHost 中的其他列表之一相关联。使用后退按钮返回到 tabhost(onResume 触发)并且列表尚未更新。我想要一个上下文菜单项来刷新当前选项卡。

我知道可以对选项卡主机中的所有视图使用一项活动,但由于多种原因,我没有选择该方法。

To put it simply. From a context menu on a TabActivity how can I initiate executing the intent for the current tab? I am trying to force a refresh.

The tabs all initiate activities displaying a subset of people names. While in one list you call up an edit activity which allows you to associate the name to one of the other lists in the TabHost. Using the back button to get back to the tabhost (onResume fires) and the list has not updated. I would like to have a context menu item to refresh the current tab.

I know about using one activity for all the views in a tabhost but for many reasons I have not chosen that method.

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

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

发布评论

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

评论(2

萌吟 2024-10-06 13:25:24

您还可以在首先设置选项卡时尝试向意图添加标志。

    Intent i = new Intent().setClass(this, YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TabHost.TabSpec spec = tabHost.newTabSpec("name")
.setIndicator("Class",res.getDrawable(R.drawable.ic_tab_something))
.setContent(intent);

    Tabhost tabHost.addTab(spec);

You can also try adding a flag to the intent when you set up the tabs in the first place.

    Intent i = new Intent().setClass(this, YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TabHost.TabSpec spec = tabHost.newTabSpec("name")
.setIndicator("Class",res.getDrawable(R.drawable.ic_tab_something))
.setContent(intent);

    Tabhost tabHost.addTab(spec);
甜中书 2024-10-06 13:25:24

我认为由于活动生命周期的原因,您在“重新启动”活动时会遇到一些问题(活动生命周期 - startActivity()) - 如果您要将 onCreate 方法内的任何逻辑移动到另一个方法中,则从 onCreate 和 onResume 调用该方法,以便它为您重建选项卡内容。

或者,您可以添加一个菜单项来调用此方法,以便 onCreate 在首次运行时调用逻辑方法,并且您的用户可以从菜单中调用它来刷新内容。

I think due to the activity lifecycle, you will have some problems 'restarting' the activity (Activity lifecycle - startActivity()) - if you were to move any logic you have inside the onCreate method into another method, then call the method from onCreate and onResume, so it rebuilds the tab content for you.

Alternatively you could add a menu item to call this method, so onCreate calls the logic method on first run, and your user can call it from the menu to refresh the contents.

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