database - Android: offline dictionary -


i developing dictionary application stores database offline. problem using autocomplete textview display suggestions. type suggestions should loaded. if don't use asynctask typing becomes slow , gives lag. , if use asynctask the, still suggestions take of time load database. meaning database search query slow , not display results quickly. please me stuck on quite long time. code below. in advance.

        autocomplete.addtextchangedlistener(new textwatcher() {          @override         public void ontextchanged(final charsequence s, int start,                 int before, int count) {             new asynctask<void, void, void>() {                 protected void doinbackground(void... params) {                     results = db.getwords(s.tostring());//arraylist                     return null;                 }                  protected void onpostexecute(void result) {                     adapter.addall(results);                 }             }.execute();         }          @override         public void beforetextchanged(final charsequence s, int start,                 int count, int after) {         }          @override         public void aftertextchanged(editable s) {             query.showdropdown();         } 

i doing in ontextchanged(). here sqlite query searching results."select word tblwords word '%s%%' group word limit 5". note database extremely large. thanks.

i notice 2 things:

you have no minimum length start searching. think doesn't make lot of sense start searching @ 1 or 2 characters, partly because way many results. it's possible starts searching @ 0 characters, perhaps it's trying add complete database adapter.

another thing notice never clear collection of adapter, add everything. bloat list unnecessary results.

a last note style-related: wouldn't use addall method, instead update list used adapter , call notifydatasetchanged() on adapter. think style, perhaps increase performance.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -