2

正如标题所说。

例如:我有 MainActivity 和 main.xml main.xml 有 WebView "@+id/WebView1"。

打开 SecondActivity 后,我希望它在 MainActivity 的 webview 上加载一个 URL。

有什么解决办法吗?

4

2 回答 2

1

在你的 MainActivity.java

WebView webView;
static WebView sWebView; // because we will use in static method

将它们放在 oncreate 方法中;

webView = (WebView )findViewById(webview);
sWebView= webView ; 

创建下面的方法

    // it is static because we will call it from second actvity 
    static loadUrl (String Url){
       sWebView.webloadUrl(url);
    }

在创建方法的第二个活动中,

MainActivity.loadUrl("your URL"); // because load url is a statci method, you can call the it from other class.
于 2012-12-01T13:03:03.707 回答
0

把你的网址放在额外的地方。

myIntet.putExtra("url", "www.abc.com");

在第二个活动中访问它。

String url = getIntent().getExtras().getString("url");

在 webview 中呈现 url。

WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl(url);
于 2012-12-01T12:56:22.797 回答