0

i wrote a function that opens a webView inside of a dialog, the problem is that the keyboard doesnt pop up when i click a textArea i tried all the solutions in this thread to no avail

this code is function in a android.support.v4.app.Fragment

    public void openWebView() {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this.getActivity());
        WebView webView = new WebView(this.getActivity());
        webView.loadUrl("http://www.google.com");
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);

                return true;
            }
        });
        alertBuilder.setView(webView);
        webView.getSettings().setJavaScriptEnabled(true);
        alertBuilder.show();
}

this is the log when i press the text area a few times:

        09-15 11:44:56.165  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode :  nextNode is NULL
        09-15 11:44:56.165  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode :  !previousNode )
        09-15 11:45:04.715  27483-27542/ngapps.socialbackground D/webview﹕ blockWebkitViewMessage= false
        09-15 11:45:04.720  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode :  nextNode is NULL
        09-15 11:45:04.720  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode :  !previousNode )
        09-15 11:45:04.720  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode :  nextNode is NULL
        09-15 11:45:04.720  27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode :  !previousNode )
Community
  • 1
  • 1
user1333057
  • 607
  • 1
  • 8
  • 19

1 Answers1

2

You can define fake keyboard like this:

 AlertDialog.Builder alert = new AlertDialog.Builder(this); 
            WebView wv = new WebView(this);
            LinearLayout wrapper = new LinearLayout(this);
            EditText keyboardHack = new EditText(this);
            keyboardHack.setVisibility(View.GONE);
            wv.getSettings().setJavaScriptEnabled(true);
            wv.loadUrl(loadUrl);
            wv.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);

                    return true;
                }
            });

            wrapper.setOrientation(LinearLayout.VERTICAL);
            wrapper.addView(wv, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
            wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);              
            alert.setView(wrapper);
Burak
  • 478
  • 1
  • 6
  • 18
  • i am writing this inside a Fragment, so i replaced "this" with "this.getActivity()", i am getting a stackoverflow exception caused by "wrapper.addView(wrapper, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);" at at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:5822) – user1333057 Sep 15 '14 at 09:09
  • I did not write "wrapper.addView(wrapper, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);" I think you made a mistake. – Burak Sep 15 '14 at 09:10
  • my bad, it works now, why is this hack necessary, it used to work on my project, i returned to this code after a couple of days and the keyboard didn't popup, is there a "non hack" solution? – user1333057 Sep 15 '14 at 09:18