android - Multiple Numbers under one contact -
i have listview custom lazy adapter attached. pull contacts phone , display them in list. having issue dealing multiple numbers. if 1 contact has multiple numbers different types appear different contacts shown below:
here code getting contact list:
public lazyadapter getcontactlist(){ contentresolver cr = mcontext.getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null); if (cur.getcount() > 0) { while (cur.movetonext()) { string id = cur.getstring(cur.getcolumnindex(contactscontract.contacts._id)); string name = cur.getstring(cur.getcolumnindex(contactscontract.contacts.display_name)); if (integer.parseint(cur.getstring(cur.getcolumnindex(contactscontract.contacts.has_phone_number))) > 0) { cursor pcur = cr.query(phone.content_uri,null,phone.contact_id +" = ?",new string[]{id}, null); while (pcur.movetonext()) { string phonetype = ""; int type = pcur.getint(pcur.getcolumnindexorthrow(phone.type)); switch (type){ case phone.type_home: phonetype = "home"; break; case phone.type_mobile: phonetype = "mobile"; break; case phone.type_work: phonetype = "work"; break; case phone.type_fax_home: phonetype = "home fax"; break; case phone.type_fax_work: phonetype = "work fax"; break; default: phonetype = "other"; break; } string phoneno = pcur.getstring(pcur.getcolumnindex(phone.number)); map = new hashmap<string, string>(); map.put(key_contact_name, name); map.put(key_contact_num, phonetype + ": " + phoneno); //map.put(key_contact_image, getstring(getphotouri(id))); contactlist.add(map); } pcur.close(); } } } adapter = new lazyadapter(getactivity(), contactlist); return adapter; }
and here lazy adapter
public view getview(int position, view convertview, viewgroup parent) { view vi=convertview; if(convertview==null) vi = inflater.inflate(r.layout.contact_list, null); textview contactname = (textview)vi.findviewbyid(r.id.contactname); // title textview contactnum = (textview)vi.findviewbyid(r.id.contactnum); // artist name imageview thumb_image=(imageview)vi.findviewbyid(r.id.list_image); // thumb image hashmap<string, string> contact = new hashmap<string, string>(); contact = data.get(position); // setting values in listview contactname.settext(contact.get(contactfragment.key_contact_name)); contactnum.settext(contact.get(contactfragment.key_contact_num)); return vi; }
how can display multiple numbers under 1 contact if have multiple numbers?
thanks
figured out answer. added position number phone number had. when adding number lazyadapter looped through array list , added numbers so:
contactactivity
public lazyadapter getcontactlist(){ contentresolver cr = mcontext.getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null); if (cur.getcount() > 0) { while (cur.movetonext()) { map = new hashmap<string, string>(); string id = cur.getstring(cur.getcolumnindex(contactscontract.contacts._id)); string name = cur.getstring(cur.getcolumnindex(contactscontract.contacts.display_name)); map.put(key_contact_name, name); if (integer.parseint(cur.getstring(cur.getcolumnindex(contactscontract.contacts.has_phone_number))) > 0) { cursor pcur = cr.query(phone.content_uri,null,phone.contact_id +" = ?",new string[]{id}, null); while (pcur.movetonext()) { string phonetype = ""; int type = pcur.getint(pcur.getcolumnindexorthrow(phone.type)); switch (type){ case phone.type_home: phonetype = "home"; break; case phone.type_mobile: phonetype = "mobile"; break; case phone.type_work: phonetype = "work"; break; case phone.type_fax_home: phonetype = "home fax"; break; case phone.type_fax_work: phonetype = "work fax"; break; default: phonetype = "other"; break; } string phoneno = pcur.getstring(pcur.getcolumnindex(phone.number)); map.put(key_contact_num + pcur.getposition(), phonetype + ": " + phoneno); } contactlist.add(map); pcur.close(); } } } adapter = new lazyadapter(getactivity(), contactlist, "contact"); return adapter; }
lazy adapter
textview contactname = (textview)vi.findviewbyid(r.id.contactname); // name textview contactnum = (textview)vi.findviewbyid(r.id.contactnum); // number hashmap<string, string> contact = new hashmap<string, string>(); contact = data.get(position); // setting values in listview contactname.settext(contact.get(contactfragment.key_contact_name)); for(int = 0; < (contact.size() - 1); i++){ contactnum.settext(contactnum.gettext() + contact.get(contactfragment.key_contact_num + i) + "\n"); }
Comments
Post a Comment