java - Android - Implement findOnPage into a WebView -


i coding app uses webview display html files. when user clicks search code ran:

public void search() {        container = (linearlayout)findviewbyid(r.id.layoutid);      nextbutton = new button(this);        nextbutton.settext("next");        nextbutton.setonclicklistener(new onclicklistener(){            @override           public void onclick(view v){                mwebview.findnext(true);            }        });        container.addview(nextbutton);       closebutton = new button(this);        closebutton.settext("close");        closebutton.setonclicklistener(new onclicklistener(){            @override           public void onclick(view v){                container.removeallviews();             }        });        container.addview(closebutton);         findbox = new edittext(this);        findbox.setminems(30);        findbox.setsingleline(true);        findbox.sethint("search");         findbox.setonkeylistener(new onkeylistener(){            @override         public boolean onkey(view v, int keycode, keyevent event){                if((event.getaction() == keyevent.action_down) && ((keycode == keyevent.keycode_enter))){                    mwebview.findall(findbox.gettext().tostring());                     try{                        method m = webview.class.getmethod("setfindisup", boolean.type);                        m.invoke(mwebview, true);                    }catch(exception ignored){}                }                return false;            }        });  } 

the code i'm using runs fine generally, bugs in android 4.0. solution presented in android browser, top bar becomes search area.

when have tried implement have failed. there way implement webview android application? more elegant , functional design use.

thank replies

edit

for users in future, bug present in following android version:

platform version        api level   version_code android 4.0.3, 4.0.4    15          ice_cream_sandwich_mr1 

other posts (such this , this discuss issue. deriving answer these sources, should trick:

try{        method m = webview.class.getmethod("findallasync", new class<?>[]{string.class});     m.invoke(mwebview, findbox.gettext().tostring());   } catch(throwable notignored){     mwebview.findall();     try {         m = webview.class.getmethod("setfindisup", boolean.type);            m.invoke(mwebview, true);      } catch (throwable ignored){} }  

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -