• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps webview.goback problems

all works fine untiil i add the script for the back button.

Code:
package com.lukemovement.gt540blog;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class GT540Blog extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        WebView myWebView = (WebView) findViewById(R.id.webview);
        myWebView.loadUrl("http://www.example.com");

        WebView myWebView1 = (WebView) findViewById(R.id.webview);

        WebSettings webSettings = myWebView1.getSettings();
        webSettings.setJavaScriptEnabled(true);

        WebView myWebView11 = (WebView) findViewById(R.id.webview);
        myWebView11.setWebViewClient(new WebViewClient());

    }

            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                if ((keyCode == KeyEvent.KEYCODE_BACK) && WebView.canGoBack()) {  <---Problem
                    WebView.goBack();  <---Problem
                    return true;
                }
                return super.onKeyDown(keyCode, event);
            }
    }

for both of the problems it displays
"Cannot make a static reference to the non-static method goBack() from the type WebView"

anyone know whats wrong with the script??
 
- First, its not a script. Code that needs to be run through a compiler is never a script.

- Why do you make three different WebViews from the same WebView id? And neither of these are specified outside the onCreate method which means only code in onCreate method can manipulate these WebViews.

- onKeyDown is trying to say that you need to have a instantiated reference to a WebView to call goBack() on.
 
Back
Top Bottom