android - Listview TextWatcher filter sorting wrong result -



android - Listview TextWatcher filter sorting wrong result -

heyy guys hav list showing list of cuisine.now sort list items hav defined edittext user type within edittext list items filtered textwatcher.but problem listview gives me wrong items.as type first character gives me 1st 6 items of list is,when type 2nd char gives me 1st item of list if character not contained in items strings.whats mistake?

public class test extends activity { edittext editsearch; linearlayout layout; string temp; private listview listview; private displaymetrics metrics; string[] values = new string[] { "american","algerian ", "andhra", "anhui", "arabian", "asian", "assamese", "awadhi", "bakery", "beijing", "bengali", "beverages" , "bhojpuri", "biryani", "cafe", "cameroonian", "canadian", "cantonese", "centrafrican", "chinese", "congolese", "continental", "desserts", "eastafrican", "egyptian", "european", "fast food", "finger food", "french", "fujian", "gaon", "german", "ghanaian", "greek", "gujrati", "hakka ", "healthy food", "hongkong", "hyderabadi", "icecream", "indian", "indonesian", "italian", "ivorian", "jain ", "japanese", "juices", "kashmiri", "kenyan", "kerala", "konkan", "lucknowi", "maasai", "maharashtrian", "malaysian", "malwani", "mangalorean", "mexican", "middleeastern", "nepalese", "northeastern", "northindian", "oriya", "parsi", "pizza", "punjabi ", "rajasthani ", "rajasthani", "sea food", "shanghai", "sushi", "thai", "tibetan", "tunisian ", "udupi", "zhejiang", "zimbabwean " }; private int mode = 1; public void onbackpressed() { // todo auto-generated method stub super.onbackpressed(); overridependingtransition (r.anim.slide_in_left, r.anim.slide_out_right); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //setcontentview(r.layout.cusinetype_activity); setcontentview(r.layout.cusinetype_activity); //layout.setbackgroundresource(r.drawable.cusine_new); //setcontentview(layout); //you might forgetting metrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(metrics); listview = new listview(this); listview = (listview) findviewbyid(r.id.listview1); listview.setfadingedgelength(0); arraylist<string> strings = new arraylist<string>(); (int = 0;i<values.length; i++) { temp=values[i]; strings.add(temp); } final mainadapter madapter = new mainadapter(this, strings, metrics); listview.setadapter(madapter); //enables filtering contents of given listview listview.settextfilterenabled(true); //pass results listviewadapter class edittext myfilter = (edittext) findviewbyid(r.id.edittext1); myfilter.addtextchangedlistener(new textwatcher() { public void ontextchanged(charsequence s, int start, int before, int count) { madapter.getfilter().filter(s); madapter.notifydatasetchanged(); } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void aftertextchanged(editable s) { } }); //listview.setbackgroundresource(r.drawable.cusine_new); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // listview clicked item index int itemposition = position; // listview clicked item value string itemvalue = (string) listview.getitematposition(position); intent in = new intent(getapplicationcontext(),nearby_mainactivity3.class); in.putextra("value",itemvalue ); startactivity(in); // show alert // toast.maketext(getapplicationcontext(), // "position :"+itemposition+" listitem : " +itemvalue , toast.length_long) // . show(); } }); } public class mainadapter extends arrayadapter<string> { private context context; private layoutinflater minflater; private arraylist<string> strings; private displaymetrics metrics_; private class holder { public textview textview; } public mainadapter(context context, arraylist<string> strings, displaymetrics metrics) { super(context, 0, strings); this.context = context; this.minflater = (layoutinflater) this.context .getsystemservice(context.layout_inflater_service); this.strings = strings; this.metrics_ = metrics; } @override public view getview(final int position, view convertview, viewgroup parent) { final string str = this.strings.get(position); log.d("timepass", str); final holder holder; if (convertview == null) { convertview = minflater.inflate( r.layout.list_item2,null); holder = new holder(); holder.textview = (textview) convertview .findviewbyid(r.id.name); holder.textview.settextcolor(0xffffffff); // holder.textview.setbackgroundresource(r.drawable.back); convertview.settag(holder); } else { holder = (holder) convertview.gettag(); } holder.textview.settext(str); animation animation = null; animation = animationutils.loadanimation(context, r.anim.slide_in_top); animation.setduration(800); convertview.startanimation(animation); animation = null; homecoming convertview; } } }

please go through this link help in sorting out problem.

the api provided give direct functionality filter info yourself. guess scheme wont you.

android listview filter android-edittext

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -