2

Hello how i can add page loading progress in it . when the page load completely then the prgress bar should up .i want to put the code in case statement . Thanks in advance . here is the code

package com.menu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MenuActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("http://www.google.com");
    mWebView.setWebViewClient(new WebViewClient());
}
public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(getApplication())
            .inflate(R.layout.menu, menu);
    return(super.onPrepareOptionsMenu(menu));
}

public boolean onOptionsItemSelected(MenuItem item) {
     switch (item.getItemId()) {
        case R.id.Menu1:
            WebView myWebView = (WebView) findViewById(R.id.webview);
            myWebView.loadUrl("http://...........com");
                myWebView.setWebViewClient(new WebViewClient());
            break;
        case R.id.Menu2:
            WebView myWebView2 = (WebView) findViewById(R.id.webview);
            myWebView2.loadUrl("http://.................com/notice.php");
            break;
        case R.id.Menu3:
            WebView myWebView3 = (WebView) findViewById(R.id.webview);
            myWebView3.loadUrl("http://...........com/original/services.php");
                myWebView3.setWebViewClient(new WebViewClient());
            break;
        case R.id.submenu:
            Toast.makeText(this, "Sub menu", Toast.LENGTH_SHORT).show();
            break;

        default: 
            Toast.makeText(this, "Sub menu", Toast.LENGTH_SHORT).show();


            ; 
    }
    return(super.onOptionsItemSelected(item));
}
}
dave.c
  • 10,910
  • 5
  • 39
  • 62
umar
  • 3,073
  • 5
  • 35
  • 45

2 Answers2

5

HI, try this..in your webview.

    mWebView.setWebChromeClient(new WebChromeClient() {

        // this will be called on page loading progress

        @Override

        public void onProgressChanged(WebView view, int newProgress) {

            super.onProgressChanged(view, newProgress);


            loadingProgressBar.setProgress(newProgress);

            // hide the progress bar if the loading is complete

            if (newProgress == 100) {

                loadingProgressBar.setVisibility(View.INVISIBLE);

            } else {

                loadingProgressBar.setVisibility(View.VISIBLE);

            }

        }

    });

refer this link

https://sites.google.com/site/cganapathi/progressbar-in-webview-ac

Ganapathy C
  • 5,989
  • 5
  • 42
  • 75
  • Thanks for the suggestion but its giving me errors and Force to close in android . In the code i have import class but still there are errors on setVisibility(View.VISIBLE) so any other solution – umar Feb 09 '11 at 17:36
  • in your layout did you add progressbar ? and in Activity did you declare and initialize progressbar with xml resource id ? then it wont give you error. this is my working code. – Ganapathy C Feb 09 '11 at 17:48
  • Thanks Ganapathy for your concern . can u update the above code which i have posted and can guide me about adding in the resource id . I am stuck from last four hours . It will be very kind of you – umar Feb 09 '11 at 17:52
  • 3
    Check this site dude... https://sites.google.com/site/cganapathi/progressbar-in-webview-ac – Ganapathy C Feb 09 '11 at 18:16
  • Thanks Ganapathy. I will try to implement in my code . Once thanks for your concern – umar Feb 09 '11 at 18:33
2

Here one can find a very good example of spinning wheel for webview

umar
  • 3,073
  • 5
  • 35
  • 45