Home » Android » android – Tab Layout tutorial incomplete?

android – Tab Layout tutorial incomplete?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve been trying to implement the tab UI described in this tutorial: https://developer.android.com/resources/tutorials/views/hello-tabwidget.html

I follow all the steps described in the process but I keep getting a runtime exception which I believe has something to do with the fact that nowhere in the tutorial I added the extra activities (songs, artists and albums) related to the content of each tab into the android manifest file.

Am I correct? is this tutorial (like many others) faulty or incomplete?

How to&Answers:

Since they seem to update these tutorials occasionally, I wouldn’t doubt they forgot to mention this part back when this question was asked. They appear to have added a mention to this requirement in the tutorial now (as of 12/20/2010) in step 2:

Duplicate this for each of the three activities, and add the corresponding tags to the Android Manifest file.

Unfortunately, since these are beginner tutorials, they should probably include what the XML tags should look like. Prior to this tutorial, they don’t mention how to add activities to the manifest (though you add an activity at the end for hiding the title bar). The markup I used was identical to that on the other question mentioned in the OPs own answer:

<activity android:name=".ArtistsActivity"></activity>
<activity android:name=".AlbumsActivity"></activity>
<activity android:name=".SongsActivity"></activity>

There is a full reference on manifest activities on the Android developer site.

Answer:

Well thanks for the advice, but I didn’t really had to use LogCat. The tutorial is indeed faulty and incomplete, the corrections are very well explained in this related post.

Issues with Android TabHost Example

I’m just amazed by the amount of mistakes in these tutorials, and by the fact that nobody has fixed them yet.

Nelson

Answer:

I was having the same problem, even after making all the corrections said above and on the following post link

the problem was the AndroidManifest, the following manifest file worked for me.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tabview.android" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".HelloTabWidget" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <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>
</application>


</manifest>