Android Question Tabhost AddTabWithIcon ??

ilan

Expert
Licensed User
Longtime User
hi

i am trying to use the tabhost view in my app and i am creating 3 pages in activity create

but i dont know why the tabs are added but without an icon.

this is my code:

B4X:
    Dim p1ic1,p1ic2,p2ic1,p2ic2,p3ic1,p3ic2 As Bitmap
  
    p1ic1 = LoadBitmap(File.DirAssets,"p1ic1.png")
    p1ic2 = LoadBitmap(File.DirAssets,"p1ic2.png")
    p2ic1 = LoadBitmap(File.DirAssets,"p2ic1.png")
    p2ic2 = LoadBitmap(File.DirAssets,"p2ic2.png")
    p3ic1 = LoadBitmap(File.DirAssets,"p3ic1.png")
    p3ic2 = LoadBitmap(File.DirAssets,"p3ic2.png")

    TabHost1.AddTabWithIcon("זמנים ",p1ic1,p1ic2,"page1")
    TabHost1.AddTabWithIcon("תפילות ",p2ic1,p2ic2,"page2")
    TabHost1.AddTabWithIcon("הגדרות ",p3ic1,p3ic2,"page3")

am i doing something wrong?


Edit: found a thread where @Erel allready said that:

Starting from Android 4 the icon will only appear if there is no text.

another question, because i am adding a new tab and not edit an existing tab should i put that code only if FirstTime True??
 

ilan

Expert
Licensed User
Longtime User
You should never create UI items only when FirstTime is true.

thanx erel, so the creating of tabpages should be in FIRSTTIME = TRUE??

because in the example here they are not... why?

https://www.b4x.com/android/forum/threads/tabhost-tutorial.6721/#content

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    Dim bmp1, bmp2 As Bitmap
    bmp1 = LoadBitmap(File.DirAssets, "ic.png")
    bmp2 = LoadBitmap(File.DirAssets, "ic_selected.png")
  
    TabHost1.AddTabWithIcon ("Name", bmp1, bmp2, "page1") 'load the layout file of each page
    TabHost1.AddTab("Color", "page2")
    TabHost1.AddTab("Animal", "page3")
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
thanx erel, so the creating of tabpages should be in FIRSTTIME = TRUE??
Based on Erels answer you should do it always when activity_create is called. NOT just when Firsttime = true
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Based on Erels answer you should do it always when activity_create is called. NOT just when Firsttime = true

the word "only" is confusing..

like this i would agree with u and also would not keep asking:

You should never create UI items when FirstTime is true.

EDIT: ok after reading it 5 times it makes more sense... :oops:
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I know that every app start activity create will be called, my question was (in different words) is a tabhost like a list?
TabHost is a UI element. UI elements cannot be declared in Process_Globals (because they hold a reference to the current activity). So you cannot treat it like a list.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Ok erel, it is now already clear for me that a tabhost is a ui element and not like a list.

Thank you anyway for making it more clear for me :)
 
Upvote 0
Top