clearFocus()和clearFocusForRemoval()之间的区别?

时间:2013-08-12 06:22:01

标签: android view focus clear

我看到了android代码:

 /**
     * Called when this view wants to give up focus. This will cause
     * {@link #onFocusChanged} to be called.
     */
    public void clearFocus() {
        if (DBG) {
            System.out.println(this + " clearFocus()");
        }

        if ((mPrivateFlags & FOCUSED) != 0) {
            mPrivateFlags &= ~FOCUSED;

            if (mParent != null) {
                mParent.clearChildFocus(this);
            }

            onFocusChanged(false, 0, null);
            refreshDrawableState();
        }
    }
/**
 * Called to clear the focus of a view that is about to be removed.
 * Doesn't call clearChildFocus, which prevents this view from taking
 * focus again before it has been removed from the parent
 */
 void clearFocusForRemoval() {
        if ((mPrivateFlags & FOCUSED) != 0) {
            mPrivateFlags &= ~FOCUSED;

            onFocusChanged(false, 0, null);
            refreshDrawableState();
        }
    }
  1. 有人可以解释一下这个区别吗?
  2. 为什么不在mParent.clearChildFocus(this);方法中调用clearFocusForRemoval()

1 个答案:

答案 0 :(得分:1)

不要太担心它。看起来它是一个冗余的包私有方法(或者说是一个非常有用的方法 - 在删除视图时由视图系统在内部调用)在4.0.4_r2.1中删除的发行版later version