android - Searching a listview when the array is in the strings xml -
i having issue function searches list. list array used attached string[]
in actual .java files moved array strings xml file implement feature of using different languages in app. therefore translating listview
anyway, understand why code doing following can't work out how solve it...
resources res = getresources(); final string[] items = res.getstringarray(r.array.societies_array); listview2 = (listview) findviewbyid(r.id.societieslist); edittext inputsearch = (edittext) findviewbyid(r.id.inputsearch); // adding items listview adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, items); inputsearch.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // when user changed text system.out.println(cs); societiesscreen.this.adapter.getfilter().filter(cs); } @override public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } @override public void aftertextchanged(editable arg0) { // todo auto-generated method stub } });
the onclick listener of thelist depend on index of list when not searched works fine when search particular option new 'first option' gets assigned new index number instead of keeping it's original
hope makes sense , have given enough code, if need else let me know
thanks
i think i've answered similar question, here. should watch "the world of listview" lecture.
basically, if use custom baseadapter, can create new mode filtered items, enabled long there in search field.
when mode enabled, items retreived filtered list instead of original list.
if don't use own baseadapter, check out this link.
Comments
Post a Comment