tags:

views:

2368

answers:

3

does not compile. Indeed: even in 1.5, this api, getIntent(), is already listed as deprecated.

The error message I get complains that getIntent() does not return a String, but setCurrentTab() expects a string.

If I guess and change the line to read:

"tabHost.setCurrentTab(1); // was setCurrentTab(getIntent())",

then it compiles, builds, but does not run. I get the "stopped unexpectedly" error message from the emulator. I cannot even get Log.d to output, so it seems that it stops 'unexpectedly' very early.

So the first and main question is: what is the correct fix to "tabHost.setCurrentTab(getIntent())" in the final line of OnCreate() in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html?

The second and simpler question is: did I guess right in replacing 'mTabHost' with tabHost in the one place where that occurs?

A: 

At the Informal Android Meetup, I was able to confirm that my first guess was in the ballpark: the line as printed in the tutorial really is wrong, it should be replaced with something like, "tabHost.setCurrentTab(0); // was setCurrentTab(getIntent())".

There was one other major omission I had to fix before I could get the HelloTabWidget Tutorial to run: Albums|Artists|SongsActivity all had to be added to the manifest, manifest.xml. Somehow, the tutorial instructions managed to omit mention of this requirement.

MattJ
and so, you should include them here (as then they would be helpful to others)
KevinDTimm
Actually, they will learn better if they type the correction themselves, figuring out how based on my description. Such learning, after all, is the real purpose of the tutorial.
MattJ
+2  A: 

Here's the problems and fixes for that particular tutorial:

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");
Ted
A: 

@Ted, thank you very much for your help!

Actually, I found out that the line:

tabHost.setCurrentTabByTag("albums");

can be omitted because you set up the label in the spec using the setIndicator() method.

spec = tabHost.newTabSpec("albums").setIndicator("Albums",
                   res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
seth