Remove Tabs from TabHost

TomDuncan

Active Member
Licensed User
Longtime User
Hi All,
Is it possible to remove tabs from a tabhost.
Or can I initialize the current tabhost.
I tested this but it will not work. Cannot display new tabs after I do thsi.

A code snippet would be lovely as I am but a :sign0104:

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
This is what I am doing at the moment.
Not working.

tabNotes.Initialize("")
tabPat.AddTab2("Notes", tabNotes)


then later

tabNotes.Initialize("tabNotes") ' maybe clears tabs?

But does not work. No error but no tabs appear

And yes I have 2 tab sets here

Tom
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Yes. You can call TabHost.RemoveView to remove the tabhost from its parent and then initialize it and add it again.

I have done what Erel suggested, remove my tabhost from the parent and initialize it and add it again but this is causing a little problem

When I remove it and initialize the TabChanged routine gets called. WOW - my program was not ready for that. Is this supposed to happed. It did not happen the first time I initialize the TabHost

B4X:
	'gCallStack.Add("CreateScreen - Before doing something with gTabs")

    If gTabs.IsInitialized = False Then
	   'gCallStack.Add("CreateScreen - new gTabs - 01")

       gTabs.Initialize("gTabs")
	   
	   'gCallStack.Add("CreateScreen - new gTabs - 02")
	   
       gTabs.Enabled = False	   
	   
	   'gCallStack.Add("CreateScreen - new gTabs - 03")	   
    Else
	   'gCallStack.Add("CreateScreen - old gTabs - 01")
	   gTabs.Enabled = False
	   
	   'gCallStack.Add("CreateScreen - old gTabs - 02")	
       gTabs.RemoveView
	   
	   'gCallStack.Add("CreateScreen - old gTabs - 03")	   
       gTabs.Initialize("gTabs")                     ' <============== TabChanged routine getting called
    End If

	'gCallStack.Add("CreateScreen - After doing something with gTabs")



IS this a BUG or a Feature of TabHost? I have since added a flag to my CreateScreen to show not completed yet, that the TabChanged routine checks but is this necessary?

Thanks for any help.

PS: Overlook the gCallStack stuff, just pushing stuff onto a list so I knew where I was and where I came from.


BobVal
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Try to call Dim gTabs As TabHost before initializing it.

I tried what you suggested but it is still triggering the message

The reason I am removing and adding the TabHost is that I that I am rebuilding the screen because of a user selection.

Does not happen in Debug mode only release (might be debug mode is running to slow?)

Simple workaround is I now check a flag in TabChanged to see if we are creating the screen.

I believe what might be causing it is that I have a TabHost that has been Initilized but NO Tabs added (because there was not data to display) then I get the data and blindly Remove the TabHost and re-initialize it - this is all that I can figure. Am going to test this idea sometime today to see if that is why it is happening.

Bob
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK, I take some of what I said back.

It turns out EVERY time initialize the TabHost it fires off a TabChanged

Can someone verify this?
 
Upvote 0
Top