Question

On a TabHost view I found there are 3 events. Click, LongClick and TabChanged. I found that only TabChanged works and I would like to use Click since the user may tap a tab and go back to the home screen and may want to tap the same tab again.

Here is the Sub Routine I used with TabChanged, but I would like to use Click instead. Maybe I need to change something in my code other than just changing the _TabChanged to _Click. If so, could you let me know what to change?

Sub tbhPagesEventHandler_TabChanged

    ToastMessageShow(tbhPages.CurrentTab,False)

    ' These will make the code easier to read.
    '-----------------------------------------
    Dim intVisitsTab As Int : intVisitsTab = 0
    Dim intMaintenanceTab As Int : intMaintenanceTab = 1

    ' Start the activity the user wants.
    '-----------------------------------
    Select tbhPages.CurrentTab

        Case intVisitsTab
            StartActivity("Visits")

        Case intMaintenanceTab
            StartActivity("Maintenance")
    End Select
End Sub
Was it helpful?

Solution

I see you found a solution, based on your comment, but thought I'd post this for future readers in case it was useful.

The 'TabHost.Click' event fires when the content of the TabHost tab is clicked, not the tab itself.

If you use the following for your code, you can see the difference (this uses tbPages as the TabHost variable):

' Displays the 0-based index of the tab being activated
Sub tbPages_TabChanged
 Msgbox("Current tab is " & tbPages.CurrentTab, "") 
End Sub

' Fires when you click inside the content of the tab page,
' not on the tab itself.
Sub tbPages_Click
  Msgbox("Current tab is " & tbPages.CurrentTab, "")        
End Sub

This means you can use the CurrentTab property to determine which page the user has selected, and react accordingly:

Sub tbPages_TabChanged
  Dim TabIdx as Int
  TabIdx = tbPages.CurrentTab    ' Get the tab just activated
  Select TabIdx
    Case 0
      ' First tab is now active
    Case 1
      ' Second tab active
    Case 2
      ' Third tab active
    Case Else
      MsgBox("Something is badly wrong! We have only three tabs", "HEY")
  End Select
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top