Veeti
Veeti

Reputation: 5300

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="@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?

Upvotes: 1

Views: 239

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

Use two ListView widgets.

Upvotes: 1

Related Questions