How to know the loading progress of a webview?

dreamworld

Active Member
Licensed User
Longtime User
When a webview load a webpage, how to know its progress?
It seems that the webview has no any progress changed event
Thanks in advance!
 

warwound

Expert
Licensed User
Longtime User
Or use WebViewExtras - which i have just updated to support the WebChromeClient onProgressChanged callback.

WebViewExtras now raises the ProgressChanged(NewProgress As Int) event, where NewProgress is an integer representing the percentage that the page has loaded:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("")
   Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
   
   Dim WebViewExtras1 As WebViewExtras
   WebViewExtras1.addWebChromeClient(WebView1, "WebViewExtras1")
   
   WebView1.LoadUrl("http://www.b4x.com/forum/basic4android-updates-questions/30863-how-know-loading-progress-webview.html")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub WebViewExtras1_ProgressChanged(NewProgress As Int)
   '   NewProgress is Current page loading progress, represented by an integer between 0 and 100. 
   Log("WebView1 loading progress: "&NewProgress&"%")
End Sub

Tested and working on my Galaxy S3.
Demo attached.

Martin.
 

Attachments

  • ProgressChanged.zip
    6 KB · Views: 833
Last edited:
Upvote 0

Idris Sardi

Member
Licensed User
Longtime User
Why if we change the screen resolution by rotating the mobile phone, the URL on webview refreshes again, how do we avoid that?
Please advise thank you
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Why if we change the screen resolution by rotating the mobile phone, the URL on webview refreshes again, how do we avoid that?

That can't be avoided - the device will destroy and recreate an Activity when the device orientation changes, that's how android works.

You can fix the orientation for a single Activity or for every Activity in your app - so that it doesn't respond to an orientation change, otherwise you have to take the Activity life-cycle into account and handle such changes.

Martin.
 
Upvote 0

nso91191

Member
Licensed User
Longtime User
347zm7q.jpg


I want to know how to do color ray animation refreshing in b4a ... ? it's example for google+ app

Please example source code for loading color ray refreshing .. it's possible ?

i found some lib there

http://www.b4x.com/android/forum/th...-android-swipetorefresh-implementation.39355/

it's possible to integrate with webview ?

@warwound @NJDude
 
Last edited:
Upvote 0

nso91191

Member
Licensed User
Longtime User
WoW I did it ..

example source here

example code is correct it or not sure but it work for me :D

Special Thank : @corwin42 AHswipetorefresh / @warwound WebViewExtras :D Good Job Bros

But i have some problem progresschange not show color bar :(
 

Attachments

  • refresh.zip
    7.6 KB · Views: 526
Last edited:
Upvote 0
Top