Cant see my WebView

mebcs

Member
Licensed User
Longtime User
I can see the text, html, in log, but the WebView is not visible.

B4X:
Sub Class_Globals
   Private pnl          As Panel
   Private HTMLWebView      As WebView 
   Private bnOK          As Button 
   Dim Done             As Boolean 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Act As Activity,FileName As String)
   Done = False
   BuildScreen(Act,FileName)
End Sub
Private Sub BuildScreen(Act As Activity,FileName As String)
   Dim ScrRowHeight As Int : ScrRowHeight = 7.5%y
   Dim ScrColWidth As Int : ScrColWidth = 10%x
   Dim colOffset As Double
   Dim HTML As String = File.GetText(File.DirAssets, FileName)
   
   pnl.Initialize("pnl")
   pnl.Color = Colors.Gray 
   Act.AddView(pnl, 10%x, 10%y, 80%x, 80%y)
   pnl.BringToFront 
   '--------------
   'Row WebView
   '--------------
   HTMLWebView.Initialize("")
   colOffset = 0.0
   SetWebView(HTMLWebView,   (1 + colOffset) * ScrColWidth,1 * ScrRowHeight, 6 * ScrColWidth,6 * ScrRowHeight)
   HTMLWebView.LoadHtml(HTML)
'   Log(HTML)
   '--------------
   'Row OK 
   '--------------
   bnOK.Initialize("bnOK")
   colOffset = 0.0
   SetButton(bnOK,  "Close", (1 + colOffset) * ScrColWidth,10 * ScrRowHeight, 6 * ScrColWidth,1 * ScrRowHeight)
End Sub

Private Sub SetWebView(obj As WebView,LPos As Int,TPos As Int,WPos As Int,HPos As Int)
   obj.Color = Colors.Blue 
   pnl.AddView(obj,LPos,TPos,WPos,HPos)
End Sub

Private Sub SetButton(bn As Button,text As String ,LPos As Int,TPos As Int,WPos As Int,HPos As Int)
   bn.text = text
   bn.Gravity = Gravity.CENTER 
   bn.TextSize = 12
   bn.TextColor = Colors.Black 
   pnl.AddView(bn,LPos,TPos,WPos,HPos)
End Sub
Private Sub bnOK_Click()
   pnl.RemoveView
   Done = True
End Sub

See attached image.
 

Attachments

  • help.jpg
    help.jpg
    29.7 KB · Views: 162

sorex

Expert
Licensed User
Longtime User
try like this

B4X:
HTMLWebView.LoadUrl("file:///android_asset/"&FileName)


also... Are you sure that view got added to the panel? maybe you only see the panel there.
 
Last edited:
Upvote 0

mebcs

Member
Licensed User
Longtime User
This code is in a library so I use log to see debug information.
When I try to log the webview url it returns null in both cases.

B4X:
   pnl.Initialize("pnl")
   pnl.Color = Colors.Gray 
   Act.AddView(pnl, 10%x, 10%y, 80%x, 80%y)
   pnl.BringToFront 
   '--------------
   'Row WebView
   '--------------
   HTMLWebView.Initialize("")
   colOffset = 0.0
'   SetWebView(HTMLWebView,   (1 + colOffset) * ScrColWidth,1 * ScrRowHeight, 6 * ScrColWidth,6 * ScrRowHeight)
   pnl.AddView(HTMLWebView,0,0,100%x,90%y)
   HTMLWebView.Visible = True
   HTMLWebView.Enabled = True
'   HTMLWebView.LoadHtml(HTML)
'   Log(HTML)
   HTMLWebView.LoadUrl("file:///android_asset/" & FileName)
   Log(HTMLWebView.Url )
   HTMLWebView.LoadUrl("http://google.com")
   Log(HTMLWebView.Url )

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
null
null
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
interesting issue.

I added a new class to a dummy project and copied this class source into it.

I copied some html file to /files and added

dim wv as myclass
wv.Initialze(activity,"myhtml.htm")

and it simply display a blue webview with my html in it?
 
Upvote 0

mebcs

Member
Licensed User
Longtime User
I added the panel, etc, to the main activity.
I then added my sub to the main activity. It loads and displays my html fine.
I have several other popup panels I use from my library so I'm not sure why it doesn't work.
This will work. So be it.......
 
Upvote 0
Top