Create a gist now

Instantly share code, notes, and snippets.

@laaptu /Events.java
Last active Aug 29, 2015

What would you like to do?
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