android - show only one of similar items in List -
i have list of numbers this:
-153 -542 -153 -153 -783 -785 -975 -153 -478
as see "153" showen 4 times want show number 1 time this:
-153 -542 -783 -785 -975 -478
edit:
i need messages numbers show 1 if similar numbers here method:
public static list<smsdata> getallnumbers(context context){ list<smsdata> smslist = new arraylist<smsdata>(); uri uri = uri.parse("content://sms/inbox"); cursor c= context.getcontentresolver().query(uri, null,null,null,null); // read sms data , store in list if(c.movetofirst()) { for(int i=0; < c.getcount(); i++) { smsdata sms = new smsdata(); sms.setbody(c.getstring(c.getcolumnindexorthrow("body")).tostring()); sms.setnumber(c.getstring(c.getcolumnindexorthrow("address")).tostring()); sms.setdate(c.getstring(c.getcolumnindexorthrow("date")).tostring()); smslist.add(sms); c.movetonext(); } } return smslist; }
i fond solution:
https://stackoverflow.com/a/19305534/3522182
tnx all.
arraylist yourlist = new arraylist(); /* add values list */ arraylist simplelist = new arraylist(); hashset hashset = new hashset(); hashset.addall(yourlist); simplelist.addall(hashset);// list has unique numbers
note: order here unexpected. if want orderd, use linkedhashset keeping same order.
Comments
Post a Comment