Android Question [Solved] - Loading a URL in a WebView

rleiman

Well-Known Member
Licensed User
Longtime User
Greetings everyone,

I'm trying out a WebView for the first time and have what probably is a stupid question, but I hope you can be patient with me. :rolleyes:

In the designer I added a WebView. In my code, I used the following code to supposedly load an URL into the WebView and match the WebView width and height to match the same from the Activity. I noticed that the width and height properties were not available as shown in the attached screen shot. I also noticed the web page is not loading up in the WebView. What's missing on my part and how do I access the width and height properties?

If you know of a link to a sample project that uses a WebView to display a web site, that would also be helpful.

Thanks.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
  
    Private WebViewABRICC As WebView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

WebViewABRICC.LoadUrl("https://mawaqit.net/en/abricc-acton-01720-united-states")

' WebViewABRICC.Width = Activity.Width
' WebViewABRICC.Height = Activity.Height
 

Attachments

  • Screenshot 2022-04-02 at 11.19.39.png
    Screenshot 2022-04-02 at 11.19.39.png
    167 KB · Views: 175
Last edited:

drgottjr

Expert
Licensed User
Longtime User
i have no problem loading the url in a webview (see attached).


WebViewABRICC seems to be the name of your webview and your class. that confuses me; not sure how the compiler reacts to it.
 

Attachments

  • cap.png
    cap.png
    81.3 KB · Views: 173
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
i have no problem loading the url in a webview (see attached).


WebViewABRICC seems to be the name of your webview and your class. that confuses me; not sure how the compiler reacts to it.
Thanks so much for the reply. Can you upload the project so I can see what I did wrong?

Thanks in advance.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I just learned a valuable lesson and am marking this post as solved. If you look at the colour of "WebViewABRICC" from the screen shot, it's black. When I displayed the Intellisence pop-up, the width and height properties were not showing up. From my blunder I discovered that every bit of code needs to be in Sub / End Sub. I added a sub procedure and put the same line that was giving me the issue into the sub procedure and the colour of "WebViewABRICC" turned purple! When I typed the full stop to display the Intellisense pop-up, it was different and even allowed me to access the width and height properties. When I ran the app, the web page loaded right up.

Well, at least it's forcing me to make sure all my coding is modular. Silly me. šŸ˜­
 
Upvote 0
Top