Incremental search in android using Volley library? -


i have somehow implemented incremental search in android using asynctask. in incremental search api called each character entered in edit text suggestions server. example,

user types -> api called. user types ab -> api called. user types abc -> api called.  

this makes 3 api calls a, ab , abc respectively. if user still typing previous requests (e.g. requests of , ab) cancelled , last request (abc) served avoid delays.

now want implement using volley library better performance. me how can achieve functionality using volley specially mechanism of cancelling previous request , serve last request suggestions server.

note: couldn't find regarding that's why posting here. please guide me because new android , in need of answer.

first need implement textwatcher listen change in edit text. depending on requirement of changed text, cancel , add request queue.

private requestqueue queue = volleyutils.getrequestqueue();   private static final string volley_tag = "vt"; private edittext edittext; ...   textwatcher textchangedlistener = new textwatcher() {            @override           public void aftertextchanged(editable s) {}            @override           public void beforetextchanged(charsequence s, int start, int count, int after) {}            @override           public void ontextchanged(charsequence s, int start, int before, int count) {              if (s.length() != 0) {                 // first cancel current request tag                 queue.cancelall(volley_tag);                 // , add new 1 queue                 stringrequest stringrequest =                       new stringrequest("http://blabla/servlet?param=" + s,                       new listener<string>() {                        // request callbacks                      };                 stringrequest.settag(volley_tag);                 queue.add(stringrequest);             }          }   };  edittext.addtextchangedlistener(textchangedlistener); 

just remember design gobble bandwidth. better way use handler.post() wait several seconds before firing request.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -