1

我希望用户能够在文本框中输入网址并使用 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);
            }
        }); 
4

2 回答 2

1

改变

webview.loadUrl(edittext);

webview.loadUrl(edittext.getText().toString());
于 2013-10-31T13:52:07.240 回答
0

你试过这个吗?

edittext = (EditText) findViewById(R.id.editText);
    button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {

        webview.loadUrl(edittext.getText().toString());
            }
        }); 
于 2013-10-31T13:55:10.363 回答