This article illustrates the Workround effect of the Android programming implementation WebView hiding the keyboard when performing loadurl. Share to everyone for your reference, specific as follows:
WebView Workround to hide the keyboard when performing Loadurl
In writing webapp, often need to use JS call Java method, Java method execution, and then callback JS function to do something, and WebView call JS is through the Loadurl method, a loadurl will hide the soft keyboard. Because each loadurl operation will call the Clearhelpers method Clearhelpers method will call the Cleartextentry method, this method will Hidesoftkeyboard, then there is no way to hide it.
There are two ways:
1 Rewrite the Loadurl method, before calling Super.loadurl, note the size of the softkeyboard, after the execution super.loadurl the SoftKeyboard display (think all crazy ...) Not in this way)
2 In another perspective, the general invocation of Java methods will interrupt the input (because the keyboard is hidden), indicating that in this period of time should be more frequent invocation of Java methods, so this should be less time to appear, Then can give WebView a javascriptinterface, will want to pass to JS parameters in this javascriptinterface provided to JAVASCIRPT code call.
The code is as follows:
Define a class:
public class Jsinterface {public
String getString () {
return "2";//here is the simplest case ...
}
}
On the WebView side:
Jsinterface = new Jsinterface ();
Webview.addjavascriptinterface (Jsinterface, "jsinterface");
To expose this javascriptinterface to JS.
On this side of the HTML JS file:
SetInterval (function () {
counter++;
var js = jsinterface.getstring ();
document.getElementById ("value"). Value = document.getElementById ("value"). Value + js;
}, 1000);
Every 1 seconds through Java to fetch data, update the interface, so that SoftKeyboard will not hide
The above example is very simple, probably most people feel useless, in fact, in the Jsinterface.getstring method can do a lot of things.
When it comes to asynctask, you need to know that all asynctask are running in one thread at first, After Android1.6 to the multithreaded operation, after Android3.0, in order to avoid a number of multi-threaded problems, and changed to a single-threaded operation, if the first to Asynctask multithreaded operation, you need to build a executor, use Asynctask.executeonexecuto The R method runs. For a specific view of Http://developer.android.com/reference/android/os/AsyncTask.html#executeOnExecutor ( Java.util.concurrent.Executor, Params ...)
I hope this article will help you with the Android program.