Florent Anders Florent Anders - 17 days ago 6
Android Question

Let a webview load a website based on text input

I'm currently programming an own search engine and I would like to load the WebView which performs the search for me with the following search:

I put an Input box on top of the layout where the user enters his search keywords, for example "Android Webview". So, when the user types on search on his Keyboard or enter, I would like to let my WebView SearchWebView load the following URL: http://searchengine.com/search= The text which was entered

How can I do that?

Thanks

Answer

The WebView documentation can help you with that!

 webview.loadUrl("http://searchengine.com/search="+textInput.getText());

To get the click on keyboard's "Done":

textView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
               webview.loadUrl("http://searchengine.com/search="+textInput.getText());
            }
            return false;
        }
    });

In your EditText xml:

   android:imeOptions="actionDone"