在 Android 的两个选项卡上使用相同的视图

发布于 2024-09-25 21:50:03 字数 869 浏览 0 评论 0原文

我正在开发一个 Android 应用程序,该应用程序的活动使用选项卡布局。有两个选项卡可在下面的 ListView 中显示的内容之间切换。

这意味着两个选项卡规范指向相同的 ListView 内容,R.id.main_list

<TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />

<FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">

     <ListView 
          android:id="@+id/main_list" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" />
 </FrameLayout>

这有点有效 - 如果我切换到选项卡#2< /em> 并回到 #1,我可以看到 ListView 并且我的数据库代码根据所选选项卡获取正确的数据。但是,当活动启动时,在选项卡更改之前无法看到 ListView。这显然是一个问题。

解决这个问题最简单的方法是什么?

I'm working on an Android application with an activity that uses a tab layout. There are two tabs which switch between the content being shown in a ListView below.

This means that the two tab specifications point to the same ListView for content, R.id.main_list:

<TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />

<FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">

     <ListView 
          android:id="@+id/main_list" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" />
 </FrameLayout>

This somewhat works - if I switch to tab #2 and back to #1, I can see the ListView and my database code gets the right data based on the selected tab. However, when the activity launches, the ListView can't be seen before tabs are changed. This is obviously a problem.

What's the least hacky way to get around this?

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

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

发布评论

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

评论(1

绿萝 2024-10-02 21:50:03

使用两个 ListView 小部件。

Use two ListView widgets.

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