Last active
August 29, 2015 14:19
-
-
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
This file contains hidden or 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 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