Android Question Tabhost&webview and orientation

Tom1s

Member
Licensed User
Longtime User
Hi

I wish to use tabhost and webview. After strugling now I get those all but webview is on top of tabs and tabs wont work even they are seen. I have made Page1 and Page2 with designer and there all is ok.

Why the orientation is not working with this?

B4X:
Globals
Private template As String
Private WebView1 As WebView
Private ph As Phone

Dim TabHost1 As TabHost ' Devlares the TabHost view   
Dim pnlPage1, pnlPage2 As Panel ' Declares the two panels


Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Page1") ' Loads "Main" layout file
    ' 1 = Portrait
    ' 2 = Landscape
    ' 9 = Reverse Portrait
    ' 8 = Reverse Landscape
    ph.SetScreenOrientation(2)
   
     pnlPage1.Initialize("Page1")
     pnlPage2.Initialize("Page2")
     TabHost1.Initialize("TabHost1")
    WebView1.Initialize("Page1")
'    WebView1.AddToActivity(pnlPage1, 0, 0, 100%x, 80%y) 'this is not working
   
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
   Activity.AddView(TabHost1, 0, 0, 100%x, 100%y)
   
   TabHost1.AddTab2("Page1", pnlPage1)
   TabHost1.AddTab2("Page2", pnlPage2)

   
   
    Dim template As String
    template = File.ReadString(File.DirAssets, "template1.html")
   
    WebView1.ZoomEnabled = False
    Dim options As Map
    options.Initialize
    CreateColumnChartOptions(options)
       
    Dim jg As JSONGenerator
    Dim html As String = template
    html = html.Replace("$TYPE$", "Bar" & "Chart")
    jg.Initialize(options)
    html = html.Replace("$OPTIONS$", jg.ToString)

    html = html.Replace("$COLUMN1$", "'string', 'Date'")
    html = html.Replace("$COLUMN2$", "'number', 'TotalSumPerDay'")
    html = html.Replace("$ROWDATA$", Main.json)
       ph.SetScreenOrientation(2)
    WebView1.LoadHtml(html)
    Log(html)
   
End Sub
 

Tom1s

Member
Licensed User
Longtime User
How about how to freeze orientation in webview?
ph.SetScreenOrientation(2) Is not working
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
Maybe that
B4X:
SetActivityAttribute(Main, android:configChanges, "orientation|keyboardHidden|screenSize")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You can set the orientation with
B4X:
SetActivityAttribute(main,android:screenOrientation, "sensorLandscape")
for the defined activity (main here)
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
I got it all working but there is a strange behavior in Graph2 Tab. Tab1 webview is ok. Tab(graph2) webview is smaller.
I could "fix" this by calling WebView2.LoadHtml(html2) in Sub TabHost1_TabChanged. It could still be seen that first webview is smaller before update is applied.
Is there something that could be done differently? Initialize first?
Thanks

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

    TabHost1.AddTab("Graph1", "page1") 'load the layout file of each page
    TabHost1.AddTab("Graph2", "page2")
    Graph1
   
   
End Sub

Sub Graph1
Dim template As String
    template = File.ReadString(File.DirAssets, "template1.html")
   
    WebView1.ZoomEnabled = False
    Dim options As Map
    options.Initialize
    CreateColumnChartOptions1(options)
       
    Dim jg As JSONGenerator
    Dim html As String = template
    html = html.Replace("$TYPE$", "Bar" & "Chart")
    jg.Initialize(options)
    html = html.Replace("$OPTIONS$", jg.ToString)

    html = html.Replace("$COLUMN1$", "'string', 'Date'")
    html = html.Replace("$COLUMN2$", "'number', 'TotalSumPerDay'")
    html = html.Replace("$ROWDATA$", Main.json)
'    WebView1.Initialize("")
    WebView1.LoadHtml(html)
    Log(html)
    Graph2
End Sub   
Sub Graph2
'Dim template2 As String
    template2 = File.ReadString(File.DirAssets, "template2.html")
   
    WebView2.ZoomEnabled = False
    Dim options As Map
    options.Initialize
    CreateColumnChartOptions2(options)
    html2=template2   
    Dim jg As JSONGenerator
'    Public html2 As String = template2
    html2 = html2.Replace("$TYPE$", "Pie" & "Chart")
    jg.Initialize(options)
    html2 = html2.Replace("$OPTIONS$", jg.ToString)

    html2 = html2.Replace("$COLUMN1$", "'string', 'ComponentName'")
    html2 = html2.Replace("$COLUMN2$", "'number', 'TotalSum'")
    html2 = html2.Replace("$ROWDATA$", Main.json2)
'    WebView2.Initialize("")
    WebView2.LoadHtml(html2)
'    Log(html)
 
Upvote 0
Top