ChipEditTextView.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:android-chip-edittextview 作者:
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(DrawableChip currentChip) {
    int start = getChipStart(currentChip);
    int end = getChipEnd(currentChip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(currentChip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(currentChip);
        try {
            if (!mNoChips) {
                DrawableChip newChip = constructChipSpan(
                        currentChip.getDelegate(), false);

                // transfer the original text.
                newChip.setOriginalText(currentChip.getOriginalText());

                editable.setSpan(newChip,
                        start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号