我希望用户能够在文本框中输入网址并使用 webview 加载它,但我收到以下错误:
error: no suitable method found for loadUrl(EditText)
webview.loadUrl(edittext);
method WebView.loadUrl(String) is not applicable
(actual argument EditText cannot be converted to String by method invocation conversion)
method WebView.loadUrl(String,Map<String,String>) is not applicable
(actual and formal argument lists differ in length)
这是我正在使用的代码:
Button button;
private EditText edittext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WebView webview = new WebView(this);
edittext = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
webview.setWebChromeClient(new WebChromeClient());
setContentView(webview);
webview.loadUrl(edittext);
}
});