Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should capture all request that are send by the website inside your webview like the submit of the data you`re interested in. Therefore you should add a WebViewClient to your WebView and implement </p> <pre><code>public bool ShouldOverrideUrlLoading (WebView view, string url) </code></pre> <p>Here is an example that I`m using to get the id of the currently (in the webview) selected feature of a map that is inside a WebView to display the corresponding details the user requested by clicking this object on the map. The JavaScript-Code is just the href that is calling a function:</p> <pre><code>"&lt;a href=\"javascript:getDetailsForSelectedStation();\"&gt;Details...&lt;/a&gt;"; </code></pre> <p>This is the function (where eventFeature is a global variable) </p> <pre><code>function getDetailsForSelectedStation() { window.location.href = "www.ANFANGP" + eventFeature.attributes.saeulenid + "PDETAILANFRAGE"; } </code></pre> <p>(You could also directly set the href to our "fake"-url) It should start like a usual adress so I used www. and then I used P to be able to tokenize the string in C#. The End-Tag "DETAILANFRAGE" will be used to catch this call in C#.</p> <p>Now this is the WebViewClient to receive the message:</p> <pre><code>class MyWebViewClient : WebViewClient { public override bool ShouldOverrideUrlLoading (WebView view, string url) { //check, whether this was a details-url if (url.EndsWith ("DETAILANFRAGE")) { //tokenize the url string[] tokens = url.Split ('P'); long saeulenid; if (long.TryParse (tokens [1], out saeulenid)) { //Here you can work with the data retrieved from the webview ShowDetailsByID(saeulenid); ... } } return true; } } </code></pre> <p>The WebViewClient has to be added to the WebView:</p> <pre><code>MyWebView.SetWebViewClient(new MyWebViewClient()); </code></pre> <p>If you need more context information you should override the constructor, too. I`m handing over the current activity to be able to start a new Activity (StartActivity() ) to display a view for details in my app. By the way, to call JavaScript code from C# you just have to load an url like: MyWebView.LoadUrl("javascript:myFunction(myParams)"); Very useful for debugging is the WebChromeClient. </p> <p><a href="http://docs.xamarin.com/android/tutorials/User_Interface/web_view" rel="nofollow">See this tutorial from xamarin for more details</a></p> <p>And of course you may find interesting information in the <a href="http://developer.android.com/reference/android/webkit/WebView.html" rel="nofollow">WebView reference</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload