java - Issues with a tagging system using Autocomplete android -
i trying implement similar facebook's search system, if user starts typing in name brings autocomplete suggestions based on letters typed, , additional option search more results. each result object , not string, , have tried adding result search every time click on search or 1 of objects replace text occurs object oppose name , know method of autocomplete widget. there way go it?
here code:
private autocompletetextview sx; sx = (autocompletetextview) findviewbyid(r.id.sx); if(sadapter == null) { sadapter = new sadapter(postactivity.this, usersfound); sx.setadapter(sadapter); } sx.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { if (sx.gettext().tostring().length() <= 3 && sadapter != null) { usersfound.clear(); sadapter.notifydatasetchanged(); } if (sx.gettext().tostring().length() > 3) { usersfound.clear(); sadapter.notifydatasetchanged(); log.d(constants.debug, "changing text " + s); sxname = s.tostring(); testcreate(); sadapter.notifydatasetchanged(); } } @override public void aftertextchanged(editable s) { } }); sx.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { databaseuser newadd = usersfound.get(position); if(position == searchserverindex) { sx.settext(sxname); usersfound.clear(); sadapter.notifydatasetchanged(); apigetpossiblecandidates(); } else { sx.settext(""); } } }); private void testcreate() { databaseuser nuser1 = new databaseuser("userid", "pictureid", "jon"); databaseuser nuser2 = new databaseuser("userid", "pictureid", "jonny"); databaseuser nuser3 = new databaseuser("userid", "pictureid", "jong"); databaseuser nuser4 = new databaseuser("userid", "pictureid", "joan"); databaseuser searchserver = new databaseuser("searchid", "pictureid", "search " + sxname); usersfound.add(nuser1); usersfound.add(nuser2); usersfound.add(nuser3); usersfound.add(nuser4); searchserverindex = usersfound.size(); usersfound.add(searchserver); if(sadapter != null) { sadapter.notifydatasetchanged(); } }
this adapter:
public class sadapter extends arrayadapter<databaseuser> { private context mcontext; private list<databaseuser> userssearch; private list<databaseuser> usersfiltered; public sadapter(context context, list<databaseuser> usersadded) { super(context, 0, usersadded); mcontext = context; userssearch = usersadded; } @override public int getcount() { return userssearch.size(); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater inflater = (layoutinflater) mcontext .getsystemservice(context.layout_inflater_service); v = inflater.inflate(r.layout.user_autosearch_item, null); } //helps recycling final viewholder holder = new viewholder(); holder.usertxt = (textview) v.findviewbyid(r.id.usertxt); v.settag(holder); string name = userssearch.get(position).getname(); holder.usertxt.settext(name); return v; } static class viewholder { textview usertxt; } }
you can override getitem() method in adapater , return object of databaseuser of particular position searchlist..
@override public databaseuser getitem(int position) { return userssearch.get(position); }
so onclick method can call method , give databaseuser object can retrive text. hope helps ..
Comments
Post a Comment