android.view.View#OnAttachStateChangeListener ( )源码实例Demo

下面列出了android.view.View#OnAttachStateChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    this.recyclerView = recyclerView;
    recyclerViewAttachStateChangeListener = new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            clear();
            recyclerView.removeOnAttachStateChangeListener(recyclerViewAttachStateChangeListener);
        }
    };
    recyclerView.addOnAttachStateChangeListener(recyclerViewAttachStateChangeListener);
    for (LocalAdapter<?> localAdapter : localAdapters) {
        localAdapter.onAttachedToRecyclerView(recyclerView);
    }
}
 
源代码2 项目: coordinators   文件: Coordinators.java
/**
 * Attempts to bind a view to a {@link Coordinator}.
 *
 * Immediately calls provider to obtain a Coordinator for the view. If a non-null Coordinator is
 * returned, that Coordinator is permanently bound to the View.
 */
public static void bind(@NonNull View view, @NonNull CoordinatorProvider provider) {
  final Coordinator coordinator = provider.provideCoordinator(view);
  if (coordinator == null) {
    return;
  }

  View.OnAttachStateChangeListener binding = new Binding(coordinator, view);
  view.addOnAttachStateChangeListener(binding);
  // Sometimes we missed the first attach because the child's already been added.
  // Sometimes we didn't. The binding keeps track to avoid double attachment of the Coordinator,
  // and to guard against attachment to two different views simultaneously.
  if (isAttachedToWindow(view)) {
    binding.onViewAttachedToWindow(view);
  }
}
 
public View.OnAttachStateChangeListener getOnAttachStateChangeListener() {
    return mOnAttachStateChangeListener;
}
 
public void setOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) {
    this.mOnAttachStateChangeListener = listener;
}
 
源代码5 项目: RxLifecycle   文件: TestUtil.java
/**
 * Manually retrieve the view's attach state change listeners of an event. Robolectric
 * doesn't currently support manually firing these, and it would seem the events are not called
 * in normal Robolectric usage either.
 *
 * @param view View with listeners to notify
 */
static CopyOnWriteArrayList<View.OnAttachStateChangeListener> getAttachStateChangeListeners(View view) {
    Object listenerInfo = ReflectionHelpers.callInstanceMethod(view, "getListenerInfo");
    return ReflectionHelpers.getField(listenerInfo, "mOnAttachStateChangeListeners");
}
 
 方法所在类
 同类方法