Get Android To Treat HTML Choose How Android Spinner?

The Android Spinner's GUI component is a typical autocomplete choke. Choosing HTML5 with a datalist is also, but unfortunately HTML5 with a datalist in Android is NOT .

Of course, Android will not support the datalist until next year (they declare). More importantly, any choice of HTML is an Android app with hacking on the tablet. On the phone, OK. On the tablet, the selection is not drop-down, but a small list is displayed at the bottom of the screen. This list has radio buttons and a Finish button. Its a weird little user interface component that fights the screen, instead of displaying a list of dropdowns. Is there any way to tell Android to do the right thing? How to do this in a desktop browser?

I used jQuery UI droplist and this is fine on the tablet, but then bad on the phone. A keyboard appears on the phone and locks the display. Is there any way to tell Android to do the right thing? To not display the keyboard for this particular html input element?

Can I tell Android to:

  • Do not show keyboard for some items?
  • Do not make this silly wart in the style of the iPad, but choose html like a normal browser, and as if they make their own spinner dropner?
+6
source share
1 answer

A bit of hacks, but it's possible. You must create a javascript bridge between the WebView and your java code.

 class JsBridge { @JavascriptInterface public void showNativeSpinner() { // show native spinner logic } } webView.addJavascriptInterface(new JsBridge(), "jsBridge"); 

In the html code you need to remove / hide the select and add somekind from the placeholder that you can click. Disabling select will not work, because the disconnected item cannot receive events (cannot be pressed). Then add the onclick callback, which invokes the bridge method. All this can be done using javascript.

 $("#my-select").hide(); $("#my-select-parent").append("<div id='placeholder'></div>"); $("#placeholder").on("click", function() { jsBridge.showNativeSpinner(); }); 

You can execute javascript`` code to the ,, javascript`` code to the WebView from the java,,, code

 webView.loadUrl("javascript:yourLogicFunction()"); 

The last thing you need to do is add OnItemSelectedListener to the spinner and to the listener method to call javascript callbacks in the WebView using the loadUrl method.

This should solve your problem :)

+1
source

Source: https://habr.com/ru/post/978622/


All Articles