有两种方式选择选项卡活动

发布于 2024-09-26 01:13:59 字数 247 浏览 0 评论 0原文

我的应用程序有三个选项卡:A、B、C,它们具有三个不同的活动。

选项卡 A 包含列表视图。用户可以选择选项卡 B 或滚动 A 中的列表视图,选择一行将带他到选项卡 B 以及所选行的位置。

如何在选项卡 B 中检测到用户已选择一行或单击选项卡 B。单击选项卡 B 选择默认值, 而在 A 中选择一行会使 B 对数据执行一些特殊操作。我可以创建一个单独的活动,在选择一行时启动该活动,但这是代码重复,我更喜欢尝试找出 B 是否可以检测到它是如何启动的。

My app has three tabs, A, B, C that have three distinct activities.

Tab A includes a list view. User can either select Tab B or scroll the list view in A, selecting a row will take him to Tab B with the position of the selected row.

How can I detect in Tab B that the user has selected a row or clicked on Tab B. Clicking on Tab B selects a default,
whereas selecting a row in A makes B do something special with the data. I could create a separate activity that is launched when a row is selected, but that is code duplication and I prefer trying to find out if B can detect how it was launched.

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

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

发布评论

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

评论(1

挽容 2024-10-03 01:13:59

使用用于启动选项卡 B 的活动的 Intent 的 Extras 属性。

例如。

当您从列表中启动选项卡 B 时,单击:

Intent tabBIntent = new Intent(this, TabB.class);
tabBIntent.putExtra("fromList", true);
startActivity(tabBIntent);

在 TabB 的 onCreate(或类似位置)中:

if (getIntent().getBooleanExtra("fromList", false))
    ....

Use the Extras attribute of the Intent you use to launch tab B's Activity.

eg.

When you launch Tab B from a list click:

Intent tabBIntent = new Intent(this, TabB.class);
tabBIntent.putExtra("fromList", true);
startActivity(tabBIntent);

in TabB's onCreate (or somewhere similar):

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