开发者

Using the same view on both tabs in Android

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="@andr开发者_如何学编程oid: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?


Use two ListView widgets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜