Android Listview with Search filter -
i trying make listview search android.i using simplecursoradapter on ontextchanged have found error adapter cannot resolved or not field.how can resolve error .i using simplecursoradapter .i not able use adapter.getfilter().filter(cs);
listview lv; cursor cursur1; edittext search ; int textlength=0; arrayadapter<string> adapter1; @suppresswarnings("deprecation") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_main); search = (edittext) findviewbyid(r.id.inputsearch); final string [] from={contactscontract.commondatakinds.phone.display_name,contactscontract.commondatakinds.phone.number,contactscontract.commondatakinds.phone._id}; int [] m={android.r.id.text1,android.r.id.text2}; lv=getlistview(); lv.setchoicemode(listview.choice_mode_multiple); cursur1=getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, null, null, null); startmanagingcursor(cursur1); @suppresswarnings("deprecation") simplecursoradapter adapter=new simplecursoradapter(this, android.r.layout.simple_list_item_2, cursur1, from,m); setlistadapter(adapter); search.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // todo auto-generated method stub mainactivity.this.adapter.getfilters().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 } }); } @override public long getselecteditemid() { // todo auto-generated method stub return super.getselecteditemid(); } @override public int getselecteditemposition() { // todo auto-generated method stub return super.getselecteditemposition(); }
}
try this.. inside add text change listener
youradapterorwhateveradapter adapter = (youradapterorwhateveradapter) listview.getadapter(); adapter.getfilter().filter(s); adapter.notifydatasetchanged()
Comments
Post a Comment