android - How to load a url into a webview when enter is pressed? -
i trying make app search website taking google url, adding text edittext, adding google's code thing website. however, have discovered small problem: need webview refresh when enter button pressed. don't know how this. help?
edit: came later, , haven't tested yet. please comment if there wrong it.
package com.example.james.northalleghenyschooldistrict; import android.app.searchmanager; import android.content.intent; import android.support.v4.app.fragmentactivity; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.keyevent; import android.view.menu; import android.view.menuitem; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.edittext; public class searchactivity extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_search); //identifies webview webview webview = (webview) findviewbyid(r.id.mywebview); //loads url webview.loadurl("about:blank"); //identifies edittext edittext edittext = (edittext) findviewbyid(r.id.edittext1); //keeps user in webview webview.setwebviewclient(new webviewclient() { public boolean shouldoverrideurlloading(webview view, string url) { return false; } }); } private void onkeyshortcut(int keycodeenter) { //identify things edittext edittext = (edittext) findviewbyid(r.id.edittext1); webview webview = (webview) findviewbyid(r.id.mywebview); //load modified url webview.loadurl("https://www.google.com/search?q=northallegheny#q=" + edittext + "%20site%3anorthallegheny.org") } }
just call webview inbuild method webview.reload();
Comments
Post a Comment