mabbas007 / TagsEditText

Android EditText for view tags or chips
Apache License 2.0
694 stars 124 forks source link

LIMIT TAGS #34

Closed aleporf closed 3 years ago

aleporf commented 7 years ago

How to set max tags inserted?

Pirksy commented 6 years ago
@Override
public void onTagsChanged(Collection<String> collection) {
    handleLimit(edFieldTag.getText().length(), collection.size());
}

@Override
public void onEditingFinished() {

}

private void handleLimit(int currentTextLength, int currentTagsCount) {
    int length = (maxTags <= currentTagsCount) ? currentTextLength : Integer.MAX_VALUE;
    edFieldTag.setFilters(new InputFilter[]{new InputFilter.LengthFilter(length)});
}