clearFocus()和clearFocusForRemoval()的区别?

问题描述 投票:1回答:1

我看到了安卓的代码。

 /**
     * 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() 方法?
android view focus
1个回答
1
投票

不用太担心这个问题。看起来这是一个多余的包-私有方法(或者说不是一个非常有用的方法--当一个视图被移除时,视图系统在内部调用),在发布版本中。4.0.4_r2.1 中删除了。新版

© www.soinside.com 2019 - 2024. All rights reserved.