Getting textarea html values ​​in Android

I have an Html page loaded on a WebView . There are four TextAreas in the HTML page that I fill after loading the page on the WebView , and when I fill them, I want to get the TextAreas values ​​when clicking Next Button on my Android ( The next button is on Android not on the Html page ), but I can’t Get TextAreas values ​​in Android. So please help me. Thanks at Advance.

Here is my Html page that I uploaded to WebView .

enter image description here

+5
source share
1 answer

On the HTML page associated with the OK button:

 function ok() { var t1 = document.getElementById("textarea1").value; var t2 = document.getElementById("textarea2").value; var t3 = document.getElementById("textarea3").value; var t4 = document.getElementById("textarea4").value; var result = JSON.parse(bridge.doIt(t1,t2,t3,t4)); } } 

In a webview application:

  class MyBridge { public MyBridge(Context context) { // ... } @JavascriptInterface public String doIt(String t1, String t2, String t3, String t4) { // do whatever you want here with the values } } 

and in the webview constructor:

  this.addJavascriptInterface(new MyBridge(pContext), "bridge"); 

This should work (using it yourself). If you do not want to use the "OK" button, you will have to change the code a little according to your needs, perhaps the "onKeyPress" function of the text fields is called.

+3
source

Source: https://habr.com/ru/post/1200597/


All Articles