1

I am trying to write some text in the body of my tabs on android this is the following code that I have.

intent = new Intent().setClass(this, Tab1.class);
spec = tabHost.newTabSpec("songs").setIndicator("Information",
                   res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(R.id.tab1Layout);
tabHost.addTab(spec);

Can someone tell me what to do in order for me to add some text to the body of the tab?

prolink007
  • 33,872
  • 24
  • 117
  • 185
user123
  • 67
  • 1
  • 6

2 Answers2

1

Here is a pretty good example of what you are looking for.

You basically just need to create a class that contains your contents for the tab and then add that to your tabhost with tabHost.addTab(yourTab);

prolink007
  • 33,872
  • 24
  • 117
  • 185
  • If it works give me points and accept the answer. This way you get points, i get points and the community knows it worked. Enjoy SO! – prolink007 Dec 27 '11 at 20:39
  • when i try to add tabHost.addTab(yourTab) it tells me to change to spec, is that right? – user123 Dec 27 '11 at 20:44
  • Did you create a class that contains the contents of your tab? If you did, you will want to add it to your tabHost once you have created an object of it. Follow that example that i gave you closely, it should help you better understand what you need to do. – prolink007 Dec 27 '11 at 20:54
  • can you be a bit more specific on what i have to do please? – user123 Dec 28 '11 at 16:42
  • That example i linked you too is very specific and gives you in detail how to do it. And it works. Try it and then let us know how it worked. – prolink007 Dec 28 '11 at 17:23
  • ok thanks, the example you gave me worked, i have another question, do you know how to insert images in the tabs? – user123 Dec 29 '11 at 16:12
  • The actual "tab" or the contents of the tab? – prolink007 Dec 29 '11 at 16:16
  • There are several ways to do this. Take a look at this for one way: http://developer.android.com/reference/android/widget/ImageView.html There are several other ways, google around for some examples. – prolink007 Dec 29 '11 at 16:24
  • i have been looking around on google, but i cant seem to find anything thats helping, and i looked at the link you gave me i dont know what code to use :S – user123 Dec 29 '11 at 16:30
  • Don't forget to +1 this answer and accept as an answer to your question. As for the image question, take a better look at the ImageView class in android and google around for examples of how to use ImageView. There are tons of them. I will work with you more on it in your other post. – prolink007 Dec 29 '11 at 16:34
  • DO you know to link buttons to a page? and how to make a word link to a page? – user123 Dec 30 '11 at 14:56
  • Do you mean, "link buttons to a tab page" and "link a word to a tab page"? Just making sure. – prolink007 Dec 30 '11 at 15:57
  • yh that is what i mean, so if someone clicks on a word it will link to another page or if someone clicks on to a button it will link to another page – user123 Dec 30 '11 at 16:26
  • Give me a +1 for this answer. =) You will need to create an onclicklistener for the button or word and then do something similar to what this question is talking about. http://stackoverflow.com/questions/2541802/android-switch-tabs-from-within-an-activity-within-a-tab – prolink007 Dec 30 '11 at 17:17
  • hi do you know how to add a map view inside of a tab? – user123 Jan 03 '12 at 17:17
  • There are little arrows about where you accepted the question. Press the up arrow. =) And i would ask a seperate question for the map view. I will keep an eye out for it. Thanks! – prolink007 Jan 04 '12 at 13:47
  • oh it says my level is not high enough to give you a +1, do you buy any chance know how to use a button to switch between tabs? any help will be much appreciated – user123 Jan 04 '12 at 13:48
  • I upvoted some of your questions, this will give you a higher score. Try voting up again shortly. I do know how to switch the tab with a button. I will try to give you a brief description in your other question. – prolink007 Jan 04 '12 at 13:59
-1

You need to attach a view to tab with by adding intent. There are lot of discussion on SO and google regarding this topic. Please do some search. You may use keywords like, "android tab view".

kosa
  • 65,990
  • 13
  • 130
  • 167
  • 1
    SO generally frowns upon answers that just say "go search". [answer] – Jack Dec 27 '11 at 20:37
  • I couldn't find any wording "go search" word is frown by SO. I read the link twice. By the way, here is what I found "Make sure your answer provides that – or a viable alternative". I hope go search with keyword is viable alternative and disappointed with down vote. – kosa Dec 27 '11 at 20:43
  • I did not say that the [answer] link said that. I said that in general (at least from what I have learned), answers that simply say "search for x" or "search for y" are not good answers. Show some code, put some effort into it. – Jack Dec 27 '11 at 20:51
  • Ok. Will put some effort. Thanks. – kosa Dec 27 '11 at 20:56
  • does anyone know how to add a map to a tab – user123 Jan 03 '12 at 17:57
  • i am unable to ask a new question as i keep receiving errors, thats why i posted on here, can you help? – user123 Jan 03 '12 at 18:19