diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java index 09a3764f1..0cfaab55d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java @@ -43,8 +43,7 @@ public final class TagsControlSet extends PopupControlSet { //private final Spinner tagSpinner; //@Autowired private TagDataService tagDataService; private final TagService tagService = TagService.getInstance(); - private final Tag[] allTags; - private final String[] allTagNames; + private final ArrayList allTagNames; private final LinearLayout newTags; private final ListView selectedTags; @@ -59,7 +58,7 @@ public final class TagsControlSet extends PopupControlSet { super(activity, viewLayout, displayViewLayout, title); DependencyInjectionService.getInstance().inject(this); this.activity = activity; - allTags = getTagArray(); + Tag[] allTags = getTagArray(); allTagNames = getTagNames(allTags); tagIndices = buildTagIndices(allTagNames); @@ -78,18 +77,18 @@ public final class TagsControlSet extends PopupControlSet { return tagsList.toArray(new Tag[tagsList.size()]); } - private HashMap buildTagIndices(String[] tagNames) { + private HashMap buildTagIndices(ArrayList tagNames) { HashMap indices = new HashMap(); - for (int i = 0; i < tagNames.length; i++) { - indices.put(tagNames[i], i); + for (int i = 0; i < tagNames.size(); i++) { + indices.put(tagNames.get(i), i); } return indices; } - private String[] getTagNames(Tag[] tags) { - String[] names = new String[tags.length]; + private ArrayList getTagNames(Tag[] tags) { + ArrayList names = new ArrayList(); for (int i = 0; i < tags.length; i++) { - names[i] = tags[i].toString(); + names.add(tags[i].toString()); } return names; } @@ -111,15 +110,21 @@ public final class TagsControlSet extends PopupControlSet { private void setTagSelected(String tag) { - int index = tagIndices.get(tag); - selectedTags.setItemChecked(index, true); + Integer index = tagIndices.get(tag); + if (index != null) { + selectedTags.setItemChecked(index, true); + } else { + allTagNames.add(tag); + tagIndices.put(tag, allTagNames.size() - 1); + ((ArrayAdapter)selectedTags.getAdapter()).notifyDataSetChanged(); + } } private LinkedHashSet getTagSet() { LinkedHashSet tags = new LinkedHashSet(); for(int i = 0; i < selectedTags.getAdapter().getCount(); i++) { if (selectedTags.isItemChecked(i)) - tags.add(allTagNames[i]); + tags.add(allTagNames.get(i)); } for(int i = 0; i < newTags.getChildCount(); i++) {