Tab Host "Reset"

noist

Member
Hello all,

I created a TabHost, that opens a different panel for each tab. If changes are made within such a panel, they remain, also if the tab is changed.

I want to "reset" the panels whenever a tab is changed, so that it always shows the tab the same way it was before any changes to it were made.

How do I do that?
I tried TabHost_TabChanged, but that doesn't really seem to do anything.
 

yttrium

Active Member
Licensed User
Longtime User
To begin with, you're going to need to make some kind of save-state for what the original screen was, and then set the screen each time the tab is changed.

Are you having trouble with the actual tab change detection, or the reset?
 
Upvote 0

noist

Member
Well, I tried this:

Sub TabHost_TabChanged

Label1.Text = "This is page 1"
Label2.Text = "This is page 2"

'End Sub

Basically there aren't many Views in the Panels, so it wouldn't take much coding to set it back to how it was before, but I don't know how to cause that by "changing tabs".
The above doesn't work.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Hello noist .. maybe try this

B4X:
Sub TabHost1_TabChanged
         
   Select Case TabHost1.CurrentTab
      Case 0      
         'reset code
      Case 1   
         'reset code         
      Case 2                        
         'and so on
   End Select
   
End Sub

Cheers mj
 
Upvote 0

noist

Member
Nothing in particular, just that nothing happens when I change the tab.

I can post the whole code for an example here:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim TabHost1 As TabHost

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

TabHost1.Initialize(100)
Activity.AddView(TabHost1, 0, 0, 100%x, 100%y)

TabHost1.AddTab("Test1","Layout1")
TabHost1.AddTab("Test2","Layout2")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub TabHost1_TabChanged

Select Case TabHost1.CurrentTab
Case 0
Msgbox("Test 1","Number 1")
Case 1
Msgbox("Test 2","Number 2")
End Select

End Sub

No Msgbox appears when I change tabs. Same if I add views to the layouts and try to do something with them.

What am I doing wrong?
 
Upvote 0
Top