Issue
I have some issue about WebView. I have some page. This page have two input fields.
We can input some text in field when the page is loading. But, can I set this fields after loading? For example, page opened and I choose some text in toolbar menu. After this text pasted in webView fields. It's really to realize? Thanks.
Solution
First let's break down the problem.
A webview will just load some HTML like a browser will. If you want to programmatically insert text into an input element in a webpage then we need to use javascript.
To Android, the webview is a view that handles its own drawing, we can interface with its methods and that's about it on a general level.
However, where these two meet is if we want to trigger some javascript to happen inside the webpage as a result of performing some action within the Android scope.
We still have to obey all of the rules that we described in our breaking down of the problem. Let's talk about it in those terms then: We need to interface with the webview's methods in such a way that it will use javascript to insert text into an input element.
So, now we know what we need:
- JavaScript to insert text into an input element
- A WebView method to use our JavaScript
The JavaScript is easy. Something like this will do the trick.
document.findElementById('my_text').value = 'My Text';
<input type='text' id='my_text' />
And thankfully there is such a WebView method we can use for this. It's fairly lengthy but quite straight forward and you can read all about it here.
Hope this helps.
Answered By - DanielLaneDC