Android search listview like dial pad search(search for both name and number) -
i created dial pad using grid view , got call log in list view, enabled search functionality call log user entered number(from gridview). how can search call log contact name also. suppose when user entered 7 showing call log containing 7 number, not showing call log containing letters p,q,r,s in contact name. have filter both same time.
dialerhomeactivity.java
calllistadapter=new customadapter(dialerhomeactivity.this, r.layout.list_row, common.calloglist); /** * enabling search filter * */ // capture text in edittext phone_num_edt.addtextchangedlistener(new textwatcher() { @override public void aftertextchanged(editable arg0) { // todo auto-generated method stub string text = phone_num_edt.gettext().tostring().tolowercase(locale.getdefault()); calllistadapter.filter(text); } @override public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } @override public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } });
customadapter.java
public class customadapter extends arrayadapter<calldata> implements filterable{ //string _heading, _comm; private activity activity; private list<calldata> listdata=null; private layoutinflater minflater=null; private arraylist<calldata> arraylist; private calldata objbean; private int listrow; public customadapter(activity context, int listrow, list<calldata> calldata) { super(context, listrow, calldata); this.listdata=calldata; this.listrow = listrow; this.activity = context; minflater = layoutinflater.from(context); this.arraylist = new arraylist<calldata>(); this.arraylist.addall(listdata); } public void filter(string chartext) { // todo auto-generated method stub chartext = chartext.tolowercase(locale.getdefault()); listdata.clear(); if (chartext.length() == 0) { listdata.addall(arraylist); }else { (calldata ob : arraylist) { if (ob.getcallnumber().tolowercase(locale.getdefault()).contains(chartext)){ listdata.add(ob); } } } notifydatasetchanged(); } @override public int getcount() { return listdata.size(); } public view getview(final int position, view convertview, viewgroup parent) { final viewholder holder; if (convertview == null || convertview.gettag() == null) { holder = new viewholder(); convertview = minflater.inflate(listrow, null); holder.calltype = (imageview) convertview.findviewbyid(r.id.call_logo_imageview); holder.callnumber = (textview) convertview.findviewbyid(r.id.callnumber_tv); holder.calldate = (textview) convertview.findviewbyid(r.id.calldate_tv); // holder.callduration = (textview) convertview.findviewbyid(r.id.callduration_tv); //holder.heading = (textview) convertview.findviewbyid(r.id.heading_tv); //holder.addimage = (imageview) convertview.findviewbyid(r.id.add_comment_imageview); holder.contactoptions_rl = (relativelayout) convertview.findviewbyid(r.id.options_rv); holder.numrellayout = (relativelayout) convertview.findviewbyid(r.id.number_rl); holder.optionsimage = (imageview) convertview.findviewbyid(r.id.option_imageview); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } calldata calldatalist=listdata.get(position); final string callnumber = calldatalist.getcallnumber(); final string contactname = calldatalist.getcontactname(); string calltype = calldatalist.getcalltype(); string calldate = calldatalist.getcalldatetime(); final string contact_call_id = calldatalist.getcall_id(); //string callduration=calldatalist.getcallduration(); if(calltype == "incoming") { holder.calltype.setimageresource(r.drawable.incoming); }if(calltype == "outgoing") { holder.calltype.setimageresource(r.drawable.outgoing); }if(calltype == "missed") { holder.calltype.setimageresource(r.drawable.missed); } if(null != contactname) { holder.callnumber.settext(contactname); }else { holder.callnumber.settext(callnumber); } // holder.calltype.settext(calltype); holder.calldate.settext(string.valueof(calldate)); //holder.callduration.settext(callduration+" sec"); notifydatasetchanged(); return convertview; } } class viewholder { public imageview optionsimage; public textview callnumber, calldate, callduration, heading; public imageview calltype, nextimage; public relativelayout contactoptions_rl, numrellayout; }
i think need use pattern matching algorithm this.