如何从选项卡之一访问包含选项卡主机的主要活动中的进度栏​​?

发布于 2024-10-02 13:59:49 字数 135 浏览 0 评论 0原文

我正在开发一个 Android 应用程序,其中有一个包含进度条和 tabhost 的主要活动。 tabhost 有 3 个选项卡。

如何从选项卡活动访问主活动中的进度栏​​?我希望能够在每个选项卡活动内发生变化时启动和停止进度条......

I am developing an android application where I have a main-activity that contains a progress bar and a tabhost. the tabhost has 3 tabs.

How do I from a tab-activity access the progress bar in the main activity? I want to be able to start and stop the progress bar when things changes inside each tab ativity...

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

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

发布评论

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

评论(2

往事风中埋 2024-10-09 13:59:49

在每个选项卡-Activity 中使用 getParent()

use getParent() in each tab-Activity

凉月流沐 2024-10-09 13:59:49

几种方法:

  1. 将类耦合在一起:创建自定义应用程序并将对 ProgressBar 的弱引用保存到字段中。在选项卡活动中使用 getApplication() 并将其转换为您的自定义应用程序。
    注意:在 Application 类中使用弱引用来防止内存泄漏 .

  2. 创建您自己的 BroadcastBroadcastReceiver,其中选项卡活动发送广播并且进度栏侦听它们:http://developer.android.com/guide/appendix/faq/commontasks.html#broadcastreceivers

  3. 阅读如何在 Activity 之间传递数据

Several ways:

  1. Couple the classes together: create a custom Application and save a weak reference to ProgressBar to a field. Use getApplication() inside tab activities and cast it to your custom Application.
    Note: Use weak reference inside your Application class to prevent memory leaks.

  2. Create your own Broadcast and BroadcastReceiver, where tab activities send broadcasts and progress bar listens to them: http://developer.android.com/guide/appendix/faq/commontasks.html#broadcastreceivers

  3. Read how to pass data between Activities.

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