gpt4 book ai didi

android - WebViewClient onKeyDown 覆盖错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:01:07 26 4
gpt4 key购买 nike

好的,所以我得到了这些错误我不知道为什么我得到这个,但它似乎对世界其他地方适用,如果有另一种方法我必须去做这件事我会改变代码但现在看来我的 eclipse 不喜欢我非常喜欢

The method onKeyDown(int, KeyEvent) of type XvGForm.XvGFormClient must override or implement a supertype method

The method onKeyDown(int, KeyEvent) is undefined for the type WebViewClient

代码

   @Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {

mWebView.canGoBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

好的,这是完整的代码

package com.xtremevisiongaming.xtremevisiongamingformapp;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.Window;
public class XvGForm extends Activity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xv_gform);

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.xtremevisiongaming.com/forum/forum.php");
mWebView.setWebViewClient(new XvGFormClient());



}
private class XvGFormClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
webview.loadUrl(url);
return true;
}


@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {

mWebView.canGoBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_xv_gform, menu);
return true;
}

}

最佳答案

您的问题是,现在 onKeyDown 函数是在 private class XvGFormClient extends WebViewClient 中声明的

您只需将一个右括号向上移动一个函数即可。我添加了一些缩进,也许这会帮助您看到它:

private class XvGFormClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
webview.loadUrl(url);
return true;
}
}

@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {

mWebView.goBack(); // go back in only the web view
return true;
}
return super.onKeyDown(keyCode, event);
}

关于android - WebViewClient onKeyDown 覆盖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14844789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com