Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with Android TabHost Example

I have been attempting to implement the 'advanced' tabwidget example from google. But, when it tries to call tabHost.addTab(spec); I get a stack trace from the debugger. Sorry, I don't have the stack trace here, but I'm wondering if others have had this same issue (as this code had a number of typo's and missing information that stopped me from even compiling.

Can anyone point me to a corrected/running version of this code?

The updated information needed are:

<activity android:name=".ArtistsActivity"></activity>
<activity android:name=".AlbumsActivity"></activity>
<activity android:name=".SongsActivity"></activity>
like image 286
KevinDTimm Avatar asked Feb 05 '10 18:02

KevinDTimm


People also ask

Which are the two child of the TabHost>?* 1 point?

This object holds two children: a set of tab labels that the user clicks to select a specific tab, and a FrameLayout object that displays the contents of that page.

What is TabWidget in Android?

Displays a list of tab labels representing each page in the parent's tab collection. The container object for this widget is TabHost .

What is TabHost in Android?

TabHost is a container that holds a set of tabs. Each tab consists of either the activity or the fragments. TabHost consists of two children of which one is FrameLayout (which is used to show the contents of the activity) and another one is TabWidget. (It is used to choose the tab which the user wants to open).


1 Answers

I spent the last hour or so going through that tutorial. Here's the problems and fixes for it that I dealt with:

Step 2: When creating your activities, if you do not create them through the manifest then you'll need to add them to the manifest manually.

Add these lines to AndroidManifest.xml:

  <activity android:name=".AlbumsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>
  <activity android:name=".ArtistsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>
          <activity android:name=".SongsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>

Step 3: You are only instructed to create the ic_tab_artists.xml file. You'll need to create one for ic_tab_songs.xml and ic_tab_albums.xml as well. You can just duplicate the ic_tab_artists.xml (or change the HelloTabView.java tab specs to use the artists.xml file for each tab).

Step 4: The third to last line under /res/layout/main has a typo (a ; instead of a :)

      android:padding="5dp" />
    </LinearLayout>
</TabHost>

Step 6: There is a typo that uses calls mTabHost instead of tabHost. Change it.

As already cited the getIntent() function on the last line isn't appropriate. I just call the tab based on it's id. eg:

tabHost.setCurrentTabByTag("albums");
like image 70
Ted Avatar answered Sep 25 '22 15:09

Ted