Skip to content

Instantly share code, notes, and snippets.

@allenatwork
Forked from f2prateek/CustomView.java
Created January 6, 2017 04:17
Show Gist options
  • Save allenatwork/ab21119d144ad817c7aacfc3cc078705 to your computer and use it in GitHub Desktop.
Save allenatwork/ab21119d144ad817c7aacfc3cc078705 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