我是android新手。我试图从用户那里获得输入,输入是网站的网址,然后在网页浏览中打开。但我找不到任何方法来做到这一点。只要我在webviewactivity中插入与用户输入相关的任何内容,该应用就会停止。 Plz告诉我如何使用webview的用户输入。感谢
答案 0 :(得分:0)
使用EditText View,获取其数据,并将其分配给某个字符串
String url = edtTextview.getText().toString()
并使用带有loadUrl()
方法的WebView打开该网址。
try
{
URL actualUrl = new URL(url);
HttpURLConnection cn = (HttpURLConnection)
actualUrl.openConnection();
methodName = cn.getRequestMethod();
view.loadUrl(url);
}
catch ( Exception err )
{
}
编辑部分:
String[] items={"Android","Bluetooth","Chrome"};
ArrayAdapter aa=new ArrayAdapter(this, android.R.layout.simple_spinner_item,items);
final Spinner spin = ( Spinner ) findViewById(R.id.spinner1) ;
spin.setAdapter(aa);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
Log.i(spin.getSelectedItem().toString(),"tag");
if ( spin.getSelectedItem().toString().equals("Bluetooth"))
{
try
{
URL actualUrl = new URL(url);
HttpURLConnection cn = (HttpURLConnection)
actualUrl.openConnection();
methodName = cn.getRequestMethod();
view.loadUrl(url);
}
catch ( Exception err )
{
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0)
{
}
});