Last active
June 11, 2018 02:57
-
-
Save f2prateek/7696362 to your computer and use it in GitHub Desktop.
Event Bus in view
This file contains 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