Code example for ViewTreeObserver

Methods: isAlive, removeOnScrollChangedListener

0
    } 
 
    private void unregisterListener() { 
        // Don't do anything if we haven't managed to patch the super listener 
        if (mSuperScrollListener != null && mViewTreeObserver != null) {
            if (mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            } 
            mViewTreeObserver = null;
        } 
    } 
 
    private void registerListener(View anchor) {
        // Don't do anything if we haven't managed to patch the super listener. 
        // And don't bother attaching the listener if the anchor view isn't 
        // attached. This means we'll only have to deal with the real VTO owned 
        // by the ViewRoot. 
        if (mSuperScrollListener != null) {
            ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver()
                    : null; 
            if (vto != mViewTreeObserver) {