android - Search and pull the results by entering the initials of the word -
how can filter result if user enters initials. example if in list item "george washington" if user enters "g w" in searchbox shows result. below class
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // listview data string products[] = {"dell inspiron", "htc 1 x", "htc wildfire s", "htc sense", "htc sensation xe", "iphone 4s", "samsung galaxy note 800", "samsung galaxy s3", "macbook air", "mac mini", "macbook pro"}; lv = (listview) findviewbyid(r.id.list_view); inputsearch = (edittext) findviewbyid(r.id.inputsearch); // adding items listview adapter = new arrayadapter<string>(this, r.layout.list_item, r.id.product_name, products); lv.setadapter(adapter); /** * enabling search filter * */ inputsearch.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // when user changed text mainactivity.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 } }); } }
you need set content provider , query provider results each time user enters letter.
Comments
Post a Comment