androidannotation的OnViewChangedNotifier

androidannotation中的OnViewChangedNotifier有什么作用?

阅读 2.7k
1 个回答

直接看代码 OnViewChangedNotifier

public class OnViewChangedNotifier {

    private static OnViewChangedNotifier currentNotifier;

    public static OnViewChangedNotifier replaceNotifier(OnViewChangedNotifier notifier) {
        OnViewChangedNotifier previousNotifier = currentNotifier;
        currentNotifier = notifier;
        return previousNotifier;
    }

    public static void registerOnViewChangedListener(OnViewChangedListener listener) {
        if (currentNotifier != null) {
            currentNotifier.listeners.add(listener);
        }
    }

    private final Set<OnViewChangedListener> listeners = new LinkedHashSet<>();

    public void notifyViewChanged(HasViews hasViews) {
        for (OnViewChangedListener listener : listeners) {
            listener.onViewChanged(hasViews);
        }
    }

}

可以很明显的看到是用来调用 onViewChanged 来通知 OnViewChangedListener 说明一个 View 状态改变了的助手类。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏