0

我有一个简单的 monodroid 问题

活动 A 调用活动 B

活动 B 有一个 webview,看起来像这样

SetContentView(Resource.Layout.webView);
WebView webView = FindViewById<WebView>(Resource.Id.webView1);
webView.Settings.JavaScriptEnabled = true;
webView.LoadUrl(url);
webView.SetWebViewClient(new dealWithWebView());

在 dealWithWebView() 中,我有这个

class dealWithWebView : WebViewClient
{
    WebView webView;

    public override void OnPageFinished(WebView view, string url)
    {
        webView = view;
        Context c = webView.Context;
        // it goes away and does something
        // calls another method in the class which returns back here
    }
}

问题是我似乎无法让它从 WebViewClient 返回,然后从“B”返回到“A”。

我该怎么做呢?

4

2 回答 2

0

你可以做类似的事情

SetContentView(Resource.Layout.webView);
WebView webView = FindViewById<WebView>(Resource.Id.webView1);
webView.Settings.JavaScriptEnabled = true;
webView.LoadUrl(url);
webView.SetWebViewClient(new dealWithWebView(this));

它使用:

class dealWithWebView : WebViewClient
{
    Activity parent;
    public dealWithWebView(Activity parent)
    {
        this.parent = parent;
    }

    public override void OnPageFinished(WebView view, string url)
    {
        var webView = view;
        Context c = webView.Context;
        // it goes away and does something
        // calls another method in the class which returns back here
        // all done - so finish the parent now
        parent.Finish();
    }
}
于 2012-06-17T20:58:59.597 回答
0

您还可以使用:

class WebViewClientCallback : WebViewClient
{
    public event EventHandler PageLoaded = delegate { };

    public override void OnPageFinished(WebView view, string url)
    {
        base.OnPageFinished(view, url);
        PageLoaded(this, EventArgs.Empty);
    }

}

用法:

clientCallback = new WebViewClientCallback();
clientCallback.PageLoaded += delegate(object sender, EventArgs e) {
    // What to do next?
    // Do the things you want to do after PageIsLoaded       
};
webview.SetWebViewClient(clientCallback);
webview.LoadData("<p>HTML-CONTENT</p>", "text/html; charset=UTF-8", null);
于 2014-02-16T10:40:21.463 回答