WebView stopLoading

enrique884

New Member
Licensed User
Longtime User
Hello,

This is my first android application. I'm just trying to display different pages using a TabHost control. This code does the trick displaying a small html notification when a tab is changed while the page loads:

B4X:
Sub tabs_TabChanged
   Select tabs.CurrentTab
      Case 0
   wvOdin.LoadHtml("<html><body><H1>Loading google..</h1></body></html>")
        DoEvents
   wvOdin.LoadUrl("http://www.google.es/")
      Case 1   
   wvOdin.LoadHtml("<html><body><H1>Loading page..</h1></body></html>")
   DoEvents
   wvOdin.LoadUrl("http://www.eltiempo.es/")
      Case 2   
   wvOdin.LoadHtml("<html><body><H1>Loading page...</h1></body></html>")
   DoEvents
   wvOdin.LoadUrl("http://www.filetopia.org/")
   End Select
End Sub

This code works if the previous page is fully loaded, but if it is still loading it will not display the "loading..." html while changing tabs. I belive I could force the control to cancel the activity using the stopLoading method in the original WebView control.

Erel, do you think you can expose that method in B4A?
Would it be possible to have a version of the updated library with the method before it is officially released?

Thank you very much for providing such an easy to use and powerful environment for android development!

Greetings from Spain,
Enrique
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I will add this feature. In the meantime you can use agraham's reflector library:
B4X:
Sub Globals
    Dim wv As WebView
    Dim Reflector1 As Reflector
End Sub

Sub Activity_Create(FirstTime As Boolean)
    wv.Initialize("wv")
    Reflector1.Target = wv
    Activity.AddView(wv, 10dip, 10dip, 300dip, 300dip)
End Sub

Sub StopLoading
    Reflector1.RunMethod("stopLoading")
End Sub

Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    If action = Activity.ACTION_DOWN Then
        wv.LoadUrl("http://www.b4x.com")
    Else If action = Activity.ACTION_UP Then
        StopLoading
    End If
End Sub
 
Top