DavidPizarro / AutoLabelUI

Android library to place labels next to another. If there is not enough space for the next label, it will be added in a new line.
Apache License 2.0
637 stars 107 forks source link

setOnRemoveLabelListener() is being invoked with position = -1 #13

Open MarcinOrlowski opened 8 years ago

MarcinOrlowski commented 8 years ago

When I attach setOnRemoveLabelListener(), it is always being invoked with position equals to -1, not the index of label. I see it comes form this code:

    if (listenerOnRemoveLabel != null) {
        if (view.getTag() instanceof Integer) {
            listenerOnRemoveLabel.onRemoveLabel(view, (Integer) view.getTag());
        } else {
            listenerOnRemoveLabel.onRemoveLabel(view, -1);
        }
    }

but addLabel(String label) does sets tag on label as label.setTag(textLabel); so it will not work.

In general the whole concept seem fundamentally broken here, as this position should be obtained dynamically, not from tag, as removing any label is not updating stored position of remaining tags' which will cause troubles when one is i.e. trying to keep labels in sync with something else. For now the only solution seem to be to use labels (strings) and then sync base on this, but it's not efficient.