1

I have an WebView app that uses multiple pages, I want to have a Activity Circle that shows that a new page is loading. As of right now when I click a link/button in the app it stays on the same page until the next one is fully loaded, this leaving users confused when they have bad connection.

I have Googled and looked here on Stack Overflow but only found questions asking how to set a loading indicator upon first launch.

I'm guessing I don't need to provide my code here.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
AlexBS
  • 45
  • 5
  • By `Activity Circle`, do you mean an **indeterminate ProgressBar**? – Phantômaxx Dec 10 '14 at 11:31
  • If you mean the one that just spins until the page is finished yes, not the one that uses percent. @DerGolem – AlexBS Dec 10 '14 at 11:34
  • `The one that uses percent` is a **determinate** ProgressBar (usually `Linear` or `non-standard, circular`). – Phantômaxx Dec 10 '14 at 11:36
  • I want the on that is indeterminate. As I understand Progress bars shows how far it has come, while activity indicators show that something is loading or being sent etc. – AlexBS Dec 10 '14 at 11:37
  • For **HTML pages** (you are using a `WebView`), an **animated GIF** is more than enough. – Phantômaxx Dec 10 '14 at 11:38
  • Yeah but how do I say that when the user clicks a link, hide the webview and show the activity circle until the new page is fully loaded? – AlexBS Dec 10 '14 at 11:39
  • You can do it **without** hiding the WebView (and stressing the user with such an **UI inconsistency**) Just as you'd do in a `dynamic HTML web page`. Clear the contents, show the GIF until the newe content is loaded. – Phantômaxx Dec 10 '14 at 11:42
  • So t's better do enable this on the HTML side and not the Android side? – AlexBS Dec 10 '14 at 11:50
  • Once you start building an HTML application... go on this way. It's useless to mix Android and HTML. I normally use WebViews only to show the User Guide (to provide something too hard for a TextView, such expanding/collapsing help branches). – Phantômaxx Dec 10 '14 at 11:56
  • possible duplicate of [Android WebView progress bar](http://stackoverflow.com/questions/2537454/android-webview-progress-bar) – Pratik Butani Dec 10 '14 at 12:22
  • http://itpeoplealwayswelcome.blogspot.in/2014/11/android-progressdialog-display-before.html – Pratik Butani Dec 10 '14 at 12:23

1 Answers1

0

As far as I can understand your question, you want to show the progress bar if the page is loading in the webview and when page is fully loaded then display the content of the page. Right ?

Here is what you can do.

getWindow().requestFeature(Window.FEATURE_PROGRESS);

webview.getSettings().setJavaScriptEnabled(true);

final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
     // Activities and WebViews measure progress with different scales.
     // The progress meter will automatically disappear when we reach 100%

     // Here you can check if the progress is = 100 or not
     if(progress == 100){
     // hide the progress bar
     // show the webview
     } else {
     // show the progress bar
     // hide the webview
     }

   }
});
webview.setWebViewClient(new WebViewClient() {
  public void onReceivedError(WebView view, int errorCode, String description, String           failingUrl) {
   Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
 }
 });

 webview.loadUrl("http://developer.android.com/");

Code reference from Webviews - Android developers

Jagdeep Singh
  • 885
  • 6
  • 18
  • You understood my request perfectly, reading the code I feel like it should work perfectly. Going to try it when I get home – AlexBS Dec 10 '14 at 13:11