CppLearner
CppLearner

Reputation: 17040

adding contents to tab layout

I followed the Android tutorial (as well as some other threads here at Stackoverflow..)

Now I want to incorporate twitter client into one of the tabs. The tutorial is this: Twitter Client

Thus far I have the following structure:

HelloTabWidget.java

MyTwitter.java (previously artists.java - also my first tab)

AlbumsActitivity.java (2nd tab)

SongsActitivity.java (3rd tab)

For each of the tabs, I have their own drawable xml (for the icons). I also have main.xml in the layout.

So now I started with the tutorial, but how do I modify main.xml when (1) no graphical display is available, and (2) this main.xml controls only the outline.

Then I thought about creating a mytwitter.xml but how do I tell the actitivty to use mytwitter.xml to display the content (while main.xml keeps the outline of the whole app's layout)?

In summary, how do I specify the content layout for each tab??? I see in HelloTabWidget.java we have setContent (refers to each tab's tab xml).

Thank you very much for any input!


Update I am posting codes. (1) HelloTabWidget.java (2) main.xml (3) MyTwitter.java

In the main.xml, I defined tabview2 (linear layout) with a button. I changed the parameter of setContentView to R.id.tabview2, but I got "force to quit"

According to CAT, I have the following errors:

05-17 10:29:14.402: ERROR/AndroidRuntime(796): FATAL EXCEPTION: main

05-17 10:29:14.402: ERROR/AndroidRuntime(796): java.lang.RuntimeException: Unable to start activity ComponentInfo{ywong02.android.HelloTabWidget/ywong02.android.HelloTabWidget.HelloTabWidget}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

What should I do? Again, I want to display, say, a button on the first tab (namely, MyTwitter)

Upvotes: 1

Views: 951

Answers (1)

ferostar
ferostar

Reputation: 7082

You have to use a layout, xml or not, in every activity. I mean every Activity must call setContentView to display its contents. If there's something that you need to reuse you can use the include tag, the same way you use it in JSP.

Upvotes: 2

Related Questions