java - List in Android: Rename duplicated items -


i want create lists follows:

  • list-item
  • list-item-1
  • list-item-2
  • list-myitem
  • list-myitem-1

as above list-item, if item's name same in next row, add suffix 1.

enter image description here

like done upto enter image description here

ok, want ask how implement this. simple solution can think of using map<string, int> keep track of item name. code this:

final map<string, integer> listnamemap = new hashmap<string, integer>();

when displaying list item name, you'll do:

final string displayedname; if (listnamemap.containskey(name)) {    integer newvalue = listnamemap.get(name).intvalue() + 1;    listnamemap.put(name, newvalue);    displayedname = name + "-" + string.valueof(newvalue); } else {    listnamemap.put(name, 0);    displayedname = name; } // use displayedname display 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -