Skip to content

Instantly share code, notes, and snippets.

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