我希望用户将搜索查询输入到搜索小部件中,然后将搜索结果显示给他们,然后当他们点击他们想要的网址时,我需要能够将该网址保存到其他网址中我申请的部分内容。
这是可能的,如果没有,那么有什么限制阻止了这个?
编辑 - 我想我会为具有webview的活动添加代码。
public class State extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupport = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.state);
if( customTitleSupport ){
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title );
}
final TextView myTitleText = (TextView)findViewById(R.id.my_title);
if( myTitleText != null ){
myTitleText.setText(R.string.app_name);
}
WebView stateBrowser = (WebView)findViewById(R.id.state_search);
stateBrowser.loadUrl("http://www.google.com/");
}
}
答案 0 :(得分:1)
您需要使用名为WebViewClient的东西
public class WebViewTestActivity extends Activity implements
View.OnClickListener {
/** Called when the activity is first created. */
Button btn = null;
WebView myWebView =null;
EditText et =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
et = (EditText) findViewById(R.id.editText1);
myWebView = (WebView) findViewById(R.id.webview);
// WebViewClient in use.
myWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
et.setText(url);
}
});
}
@Override
public void onClick(View source) {
if (btn.getText().equals("Go!")) {
myWebView.loadUrl(et.getText().toString());
}
}
}
`