I want to change the text in a GoogleForm via Webview, however the action happens twice.
In the text box, it has the word twice, as if the javascript happens twice.
Would you have an idea? Thanks
public class QuestionnaireFragment extends Fragment {
//Lancement de l'activité
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_questionnaire, container, false);
WebView view = (WebView) rootView.findViewById(R.id.webview_questionnaire);
String url = "LINK GOOGLE FORMS";
WebSettings webSettings = view.getSettings();
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
view.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String js ="javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].focus(); document.execCommand('insertText', false, '" + "WORD"+ "');";
view.loadUrl(js);
}
});
return rootView;
}
}
EDIT : I change string by :
String js= "javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].value=\"WORD\";";
But another probllem:
In case 1 the word was repeated twice. In case 2 the hint was not going. So, if we use both the lines of code, we can solve the problem. So just do this and it will work:
view.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String js ="javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].focus(); document.execCommand('insertText', false, '" + ""+ "');";
view.loadUrl(js);
String js2 = "javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].value=\"WORD\";";
view.loadUrl(js2);
}
});