views:

22

answers:

0

Hi,

I have been messing around with the webview function trying to add a progress bar to the webpage when it is loading. I have added a progress dialog for the transition to the webpage but now I want to add a progress bar to the webpage everytime the user clicks a link, I have tried adding different code but cannot get anything to work, either the progress bar does not show, I get errors or the default browser opens.

How can I add a progress bar to the exsisting code and keep the progress dialog;

public class official extends Activity {

private ProgressDialog progressBar; public WebView webview;

private static final String TAG = "Main";

@Override

public void onStart()

{ super.onStart();

CookieSyncManager.getInstance().sync();

}

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Bundle extras = this.getIntent().getExtras(); int webb = extras.getInt("webb");

setContentView(R.layout.browser1);

CookieSyncManager.createInstance(this);

CookieSyncManager.getInstance().startSync();

webview = (WebView) findViewById(R.id.webview); webview.setWebViewClient(new testClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true);

     if (webb == 1)   webview.loadUrl("http://bcafc.livewwware.co.uk/viewforum.php?f=7&sid=009c462b00069f307ef6dcd09e747f7c");
else if (webb == 2)   webview.loadUrl("http://www.claretandbanter.com/forum.php");

progressBar = ProgressDialog.show(official.this, "", "Loading Page...");

    }


    private class testClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Log.i(TAG, "Processing webview url click...");
    view.loadUrl(url);
    return true; 



    }





    public void onPageFinished(WebView view, String url) {
    Log.i(TAG, "Finished loading URL: " +url);
    if (progressBar.isShowing()) {
    progressBar.dismiss();

    }
    }
    }



    public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { 
    webview.goBack(); 
    return true; 
    }
    if (keyCode == KeyEvent.KEYCODE_SEARCH) {

    Intent z = new Intent(this, official.class);
    startActivity(z);

    } 
    return super.onKeyDown(keyCode, event); 
    }




    public boolean onCreateOptionsMenu (Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmen, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected (MenuItem item) {
    switch (item.getItemId()) {
    case R.id.home:
    Intent m = new Intent(this, Tabs.class);
    startActivity(m);
    return true;

    case R.id.refresh:
    webview.reload();
    Toast.makeText(this, "Refreshing...", Toast.LENGTH_SHORT).show();
    return true;


    }
    return false;
    }

    public void onStop()
    {
    super.onStop();
    CookieSyncManager.getInstance().sync();

    }




    }