Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting values of textarea of html in Android

I have an Html page loaded on WebView. There are four TextAreas present in Html page which I fill after the page loaded on WebView and when I filled them, I want to get the values of TextAreas on click of Next Button in my Android (Next Button is in Android not in Html Page) but, I cant get the values of TextAreas in Android. So please Help me. Thanks in Advance.

Here is my Html page that I Loaded on WebView.

enter image description here

like image 268
Chintan Avatar asked Oct 21 '22 03:10

Chintan


1 Answers

In the HTML page, linked to an "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 the application's webview:

  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's constructor:

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

This should work (using it myself). If you don't want to use an OK button, you'll have to change the code a bit to fit your needs, maybe call a function on the "onKeyPress" of the text fields.

like image 154
Wildcopper Avatar answered Oct 23 '22 09:10

Wildcopper