Android Question TabHost "Noob Question but need help"

Noize

Member
Licensed User
Longtime User
Hi friends,

I'm trying to build my first app with b4a, beginning with app design I found my first problem:

I Have
Main
Page1 With 2 Button
Page2 With 1 Edittext & Webview
Page3 With 2 Button

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If FirstTime = True Then
        Activity.LoadLayout("main") ' Loads "Main" layout file
        TabHost1.AddTab("Principal","Page1") ' Adds Page1 on the first Tab
        TabHost1.AddTab("Navegador","Page2") ' Adds Page2 on the second Tab
        TabHost1.AddTab("Otros","Page3") ' Adds Page3 on the third Tab
    End If
End Sub

Main shows a Tabhost and it shows all the "pages tab" correctly, but, not the content of these pages,
Buttons and Webview, and Edittext are created with the Designer.

I Know it's maybe a noob question but, I'm a begineer! :), also I know that I have to probably Initialize, or make Visible the objects, I've tried it without luck.
I've tried to detect the current tab and then make the action but, I don't know if I am on the correct wat to do this

Thanks for help me.

Cheers.
 

Noize

Member
Licensed User
Longtime User
Yes I've followed the tutorial, but, I don't understand how to "build" the design of the app, I added a Tabhost on the main app and created 3 pages in the designer.

When I launch the app it shows the TabHost and it's no problem, it works ok but, my problem is that I can't see the objects contained on that Pages.

Sorry for my english and thanks for help me
 
Upvote 0

Noize

Member
Licensed User
Longtime User
I solved the problem creating a panel on every page and creating the objects inside this panel, this is the code of the app

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Page1, Page2, Page3 As Panel                 ' Declares the three panels
    Dim TabHost1 As TabHost                         ' Declares the TabHost view
    Private fbbutton, twbutton, localiza, camara As Button  ' Declares the buttons
    Private vistaweb As WebView                      ' Declares the WebView
    Private textoedit As EditText                    ' Declares the EditText
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")
        Activity.LoadLayout("main")                         ' Loads "Main" layout file
        TabHost1.AddTab("Principal", "Page1")                 ' Adds Page1 on the first Tab
        TabHost1.AddTab("Navegador", "Page2")                 ' Adds Page2 on the second Tab
        TabHost1.AddTab("Otros", "Page3")                     ' Adds Page3 on the third Tab
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Activity.Finish
End Sub

Sub TabHost1_TabChanged
    Activity.Title = "Current Tab = " & TabHost1.CurrentTab 'Shows currentab
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
Dim Answ As Int
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Answ = Msgbox2("¿Quieres salir?", _
        "PetPopular", "Yes", "", "No", Null)
    If Answ = DialogResponse.NEGATIVE Then
        Return True
    End If
    End If
    Return False
End Sub
 
Upvote 0
Top