android - dynamically hide or show TextView in ListView's rows corresponding to title's first character -
i need hide or show label of listview's row if first character of title matched first time in list. attach picture can understand clearly.
i tried when create arraylist of contacts :
public arraylist<contactitem> getdisplaycontacts(context context) { arraylist<contactitem> contactslist = null; databasehandler db = new databasehandler(context.getapplicationcontext()); try { dao<contactitem,integer> daosubject = db.getcontactdao(); contactslist = (arraylist<contactitem>) daosubject.queryforall(); } catch(exception e) {e.printstacktrace();} collections.sort(contactslist, new comparator<contactitem>() { @override public int compare(contactitem lhs, contactitem rhs) { return lhs.getname().compareto(rhs.getname()); } }); (int =0; i< contactslist.size()-1;i++) { if (!contactslist.get(i).getname().substring(0,1).equalsignorecase(contactslist.get(i+1).getname().substring(0,1))) contactslist.get(i).setcontactlabel(true); else contactslist.get(i).setcontactlabel(false); } return contactslist; }
but didn't proper result. tried put views in custom arrayadapter , change after listview created, didn't help. check title , show/hide label in getview didn't help. grateful help.
first of - remember positions 'letter-item' should be. 'a' 0, 'b' = number of 'a'-started names, 'c' = 'b' postition + number of 'b'-started items , on. let sparsearray string type.
when got of this, should put data sparsearray, each item inex adjusted previous calculation. example, alex - 1(0 'a'-label,), bob - 3(2 'b'-label) , on.
then write custom adapter , override method
public view getview(int position, view convertview, viewgroup parent)
so, if 'position' contains in first array, return 'label'-view proper latter, otherwise, common row item accessing second array.
english not native, might hard understand - don't hesitate ask questions.
Comments
Post a Comment