Implement a getFilter() in ArrayAdapter android listview -
in list view have 4 text view , images.
i want set filter on txtcompany text view
i trying implement getfilter() provide wrong result
please help me how can implement getfilter() in listview
list view arrayadapter source code class info extends arrayadapter {
button imageview; textview txtcompany; textview txtdesc; textview txtposition; textview txtstate; textview txtcity; string[] companyarray; string[] positonarray; string[] cityarray; string[] statearray; string[] descarray; string[] contry; string[] pass; arraylist<string> receicevalueofadapter=new arraylist<string>(6); arraylist<string> time=new arraylist<string>(6); context context; data(context c, string[] company, string[] position, string[] city, string[] state,arraylist<string> receivevalue, string[] desc,arraylist<string> time1, string[] pass,string[] contry) { super(c,r.layout.list_item,r.id.txt_company,company); this.context=c; this.pass=pass; this.companyarray=company; this.positonarray=position; this.cityarray=city; this.statearray=state; this.receicevalueofadapter=receivevalue; this.descarray=desc; this.time=time1; this.contry=contry; } public view getview(int position, view convertview, viewgroup parent) { final string description; string upperstring=""; layoutinflater minflater = (layoutinflater) context.getsystemservice(activity.layout_inflater_service); view row; row=minflater.inflate(r.layout.list_item, parent,false); txtcompany = (textview) row.findviewbyid(r.id.txt_company); imageview = (button) row.findviewbyid(r.id.img); //imageview.setvisibility(view.invisible); txtposition= (textview) row.findviewbyid(r.id.txt_position); txtcity= (textview) row.findviewbyid(r.id.txt_city); txtstate= (textview) row.findviewbyid(r.id.txt_state); if(companyarray[position].tostring().length()>0) upperstring = companyarray[position].substring(0,1).touppercase() + companyarray[position].substring(1); txtcompany.settext(" "+upperstring); txtposition.settext(" "+positonarray[position]); log.d("city",statearray[position]+"city "+cityarray[position]); if(cityarray[position].tostring().length()==0) { txtcity.settext(statearray[position]); } if(statearray[position].tostring().trim().length()==0) { txtcity.settext(" "+cityarray[position]); } if(statearray[position].tostring().trim().length()<2 && cityarray[position].tostring().trim().length()<2) { txtcity.settext(" "+contry[position]); } if(statearray[position].tostring().trim().length()>=2 && cityarray[position].tostring().trim().length()>=2) { txtcity.settext(" "+cityarray[position]+", "+statearray[position]); } txtstate.settext(""+time.get(position)); imageview.settag(receicevalueofadapter.get(position)); description= descarray[position]; final int l=position; imageview.setonclicklistener(new onclicklistener() { @override public void onclick(final view v) { // toast.maketext(contect, ""+ txtposition.gettext().tostring(), toast.length_long).show(); try{ string strurl1=pass[l].trim(); string strurl= strurl1.trim(); if (!strurl.trim().startswith("https://") && !strurl.trim().startswith("http://")){ strurl = "http://"+ strurl; } intent ii = new intent(intent.action_view); ii.setdata(null); ii.setdata(uri.parse(strurl)); startactivity(ii); } catch(exception e) { } } }); homecoming row; } } edittext alter listener java code
lstsearch.addtextchangedlistener(new textwatcher() { public void beforetextchanged(charsequence charsequence, int i, int i1, int i2) { } public void ontextchanged(charsequence charsequence, int i, int i1, int i2) { main_listview.this.datadap.getfilter().filter(charsequence); } public void aftertextchanged(editable editable) { } });
you can create custom method this.
public void filter(string chartext,int flag) { if(flag==0){ chartext = chartext.tolowercase(locale.getdefault()); if (chartext.length() == 0) { listofdetails.addall(arraylist); } else { (listofdetails wp : arraylist) { if (wp.getcountry().tolowercase(locale.getdefault()).contains(chartext)) { newlist.add(wp); } } } elseif { ///do code } } android android-listview
No comments:
Post a Comment