在 Android 的两个选项卡上使用相同的视图
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用两个
ListView
小部件。Use two
ListView
widgets.