开发者

ListActivity is not showing up when added as content of a TabActivity

开发者 https://www.devze.com 2023-03-20 06:48 出处:网络
I\'m trying to present a ListActivity in a TabActivity, and for some reason the ListActivities simply will not show up. All I get is a blank space beneath the tabs.

I'm trying to present a ListActivity in a TabActivity, and for some reason the ListActivities simply will not show up. All I get is a blank space beneath the tabs.

TabActivity: https://picasaweb.google.com/FlyingYellow/Misc#5629459368100202146 ListActivity: https://picasaweb.google.com/FlyingYellow/Misc#5629459406832281026

I have absolutely no idea why this is happening. I've searched around and have only found posts about input issues. I can't even get my content to display!

TabActivity.onCreate()

 super.onCreate(savedInstanceState);
 setContentView(R.layout.browser);


 Resources res = getResources();
 TabHost tabHost = getTabHost();
 TabHost.TabSpec spec;
 Intent intent;


 intent = new Intent(this, ArtistBrowser.class);

 spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 intent = new Intent(this, AlbumBrowser.class);
 spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 intent = new Intent(this, TrackBrowser.class);
 spec = tabHost.newTabSpec("tracks").setIndicator("Tracks", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 tabHost.setCurrentTab(0);

(I followed the Android docs tutorial)

/res/layout/browser.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <LinearLayout
      android:orientation="vertical"
  开发者_如何学Go    android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:padding="5dp">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />    <--- this was the error
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp" />
  </LinearLayout>
</TabHost>


Once again, I've discovered I'm an idiot. Just in case anyone else runs into this error, my problem was I set the TabWidget's height to match_parent without thinking. I figured this out by making the TabWidget and FrameLayout different colors and saw that the entire screen was red. Christ, I need to be more careful.

0

精彩评论

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

关注公众号