java - Using Textwatcher with a simpleexpandablelistview in Android -


in previous app, had listview , and edittext @ bottom of it. have been using textwatcher in edittext filter listview. contents of listview come simplecursoradapter.

 edittext.addtextchangedlistener(filtertextwatcher);          cursor.setfilterqueryprovider(new filterqueryprovider() {             @override             public cursor runquery(charsequence constraint) {                 cursor cursor=mdbhelper.fetchfilterednotes(edittext.gettext().tostring());                 return cur;             }         });  private textwatcher filtertextwatcher = new textwatcher() {          public void aftertextchanged(android.text.editable s) {         };          public void beforetextchanged(charsequence s, int start, int count, int after) {};          public void ontextchanged(charsequence s, int start, int before, int count) {             simplecursoradapter.getfilter().filter(s.tostring());         };     }; 

in current app, have expandablelistview. use similar feature filtering content of expandablelistview.

am not sure if can make use of textwatcher this. there other way done or can use textwatcher in well. ?

this relevant portion of code:

private dbadapter mdbhelper;     list<map<string, string>> groupdata,groupdatacat; list<list<map<string, string>>> childdata,childdatacat; map<string, string> curgroupmap; list<map<string, string>> meaning=null; map<string, string> curchildmap; private static final string word = "word"; private static final string meaning = "meaning"; simpleexpandablelistadapter madapter; expandablelistview elvcat;   temp=mdbhelper.fetchallnotes(); temp.movetofirst(); getactivity().startmanagingcursor(temp);  if(temp.movetofirst()){    groupdatacat = new arraylist<map<string, string>>();    childdatacat = new arraylist<list<map<string, string>>>();         (int = 0; < temp.getcount(); i++) {         map<string, string> catgroupmap = new hashmap<string, string>();         groupdatacat.add(catgroupmap);         catgroupmap.put(word, temp.getstring(temp.getcolumnindexorthrow(dbadapter.key_word)));          list<map<string, string>> meaning = new arraylist<map<string, string>>();          map<string, string> catchildmap = new hashmap<string, string>();          meaning.add(catchildmap);          catchildmap.put(meaning, temp.getstring(temp.getcolumnindexorthrow(dbadapter.key_meaning)));          childdatacat.add(meaning);          temp.movetonext();        }     }      madapter = new simpleexpandablelistadapter(             wordlistfragment.this.getactivity(),             groupdatacat,             r.layout.word_list_item,             new string[] {word},             new int[] { r.id.tvword },             childdatacat,             r.layout.meaning_list_item,             new string[] {meaning},             new int[] { r.id.tvmeaning}     );    view=inflater.inflate(r.layout.word_list_temp, container, false);     elvcat = (expandablelistview) view.findviewbyid(r.id.elvword);     elvcat.setadapter(madapter);       return view; } 

the way got work in ontextchanged() method, called function query database , filtered data. repopulate expandable listview again based on query results.

private void populatelist(string filter) {             temp = mdbhelper.fetchsugnotes(filter);           temp.movetofirst();         this.startmanagingcursor(temp);         groupdatacat = new arraylist<map<string, string>>();         childdatacat = new arraylist<list<map<string, string>>>();          (int = 0; < temp.getcount(); i++) {             map<string, string> catgroupmap = new hashmap<string, string>();             groupdatacat.add(catgroupmap);             catgroupmap.put(word, temp.getstring(temp                     .getcolumnindexorthrow(dbadapter.key_word)));              list<map<string, string>> meaning = new arraylist<map<string, string>>();             map<string, string> catchildmap = new hashmap<string, string>();             meaning.add(catchildmap);             catchildmap.put(meaning, temp.getstring(temp                     .getcolumnindexorthrow(dbadapter.key_meaning)));             childdatacat.add(meaning);             temp.movetonext();         }          madapter = new simpleexpandablelistadapter(this, groupdatacat,                 r.layout.word_list_item, new string[] { word },                 new int[] { r.id.tvword }, childdatacat,                 r.layout.meaning_list_item, new string[] { meaning },                 new int[] { r.id.tvmeaning });          elvcat.setadapter(madapter); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -