Android 选项卡 - 开始一个新活动

发布于 2024-08-16 10:01:00 字数 157 浏览 3 评论 0原文

TabHost 中有 4 个选项卡,分别是 A、B、C 和 D。现在每个选项卡只是一个索引页,单击其中任何一个选项卡都会显示不同的活动。

问题是,当用户从选项卡中显示的内容中选择某些内容时,我需要启动另一个活动。其他活动也应该显示在父选项卡本身中。是否可以?或者我必须尝试别的东西吗?

There are 4 Tabs in a TabHost, let them be A, B, C, and D. Now each one is just an index page and clicking on any of them shows a different activity.

The problem is that I need to start another activity when the user selects something from the content displayed in the tab. The other activity should also be displayed in the parent tab itself. Is it possible? Or will I have to try something else?

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

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

发布评论

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

评论(5

≈。彩虹 2024-08-23 10:01:00

您不能更改选项卡的 contentView 而不是启动新的 Activity 吗?

也许我错了,但我认为在选项卡中启动活动是不可能的,因为 TabView 托管在活动中,而不是相反(Tabview 不托管每个选项卡的活动)。

Can't you change the contentView of your tab instead of starting a new Activity ?

Maybe I'm wrong but I think also that starting an activity in a tab isn't possible because the TabView is hosted in a activity and not the opposite (Tabview don't host an activity per Tab).

水波映月 2024-08-23 10:01:00

我认为普遍的共识是,由于这些限制,最好不要使用单个活动作为选项卡内容。请参阅这些问题和答案以获取替代方案的指针:

Android:为什么不应该我在选项卡内使用活动?
Android - 选项卡、MapView、选项卡内的活动

I think the common consensus is that it is best not to use individual Activities as tab content due to these limitations. See these questions and answers for pointers to alternatives:

Android: Why shouldn't I use activities inside tabs?
Android - Tabs, MapView, activities within tabs

反目相谮 2024-08-23 10:01:00

总结鲁克马尔·迪亚斯提供的链接。您要做的如下:

  1. 将当前 Activity(位于选项卡中)更改为从 ActivityGroup 派生 为要切换
  2. 到的 Activity 创建一个新意图
  3. 复制/粘贴并在当前 Activity 中调用此函数,其中“id”为您要切换到的新 Activity 的布局的“android:id”

     public void ReplaceContentView(String id, Intent newIntent){
          视图视图 = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); 
          this.setContentView(视图);}
    

这是我如何制作的示例调用以从我当前的选项卡式活动切换视图:

public void switchToNextActivity(View view)
{
    Intent myIntent = new Intent(getApplicationContext(), MyNextActivity.class);
    replaceContentView("next_activity", myIntent);
}

To summarize the link that Rukmal Dias provided. Here's what you do:

  1. Change your current Activity (that's in a tab) to derive from ActivityGroup
  2. Create a new intent for the Activity you want to switch to
  3. Copy/Paste and call this function in your current activity where "id" is the "android:id" for the layout of the new activity you want to switch to

     public void replaceContentView(String id, Intent newIntent){
          View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); 
          this.setContentView(view);}
    

Here's an example of how I make the call to switch views from my current Tabbed Activity:

public void switchToNextActivity(View view)
{
    Intent myIntent = new Intent(getApplicationContext(), MyNextActivity.class);
    replaceContentView("next_activity", myIntent);
}
ゃ人海孤独症 2024-08-23 10:01:00

它失去了视图层次结构。当您按下后退按钮时,就我而言,应用程序将关闭。

It looses the view hierarchy. When you press the back button, in my case, the app closes.

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