-
-
Save allenatwork/ab21119d144ad817c7aacfc3cc078705 to your computer and use it in GitHub Desktop.
Event Bus in view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomView extends View { | |
private final Bus bus; | |
public CustomView(Bus bus, ....) { | |
super(....); | |
this.bus = bus; | |
} | |
@Override protected void onAttachedToWindow() { | |
super.onAttachedToWindow(); | |
bus.register(this); | |
} | |
@Override protected void onDetachedFromWindow() { | |
bus.unregister(this); | |
super.onDetachedFromWindow(); | |
} | |
@Subscribe public void onEvent(Event event) { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment