Skip to content

Instantly share code, notes, and snippets.

@laaptu
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laaptu/1504988a90b28d59bd6b to your computer and use it in GitHub Desktop.
Save laaptu/1504988a90b28d59bd6b to your computer and use it in GitHub Desktop.
Making a single class to hold all the Events that would be posted and listened by EventBus
public class Events {
public abstract static class Event {
public String getTag() {
return this.getClass().getSimpleName();
}
}
public static class SearchResultEvent extends Event {
public int resultCount;
public SearchResultEvent(int resultCount) {
this.resultCount = resultCount;
}
}
public static class SwipeRefreshCancelEvent extends Event {
public boolean enableRefresh;
public SwipeRefreshCancelEvent(boolean enableRefresh) {
this.enableRefresh = enableRefresh;
}
}
}
///Accessing the events like this
public void onEvent(Events.Event event) {
System.out.println("Event received "+event.getTag());
if (event.getTag().equals("SearchResultEvent")) {
System.out.println("SearchResultEvent");
} else if (event.getTag().equals("SwipeRefreshCancelEvent")) {
System.out.println("SwipeRefreshCancelEvent");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment