Last active
August 29, 2015 14:01
-
-
Save parallelcross/f9571d89e9c49d95bde1 to your computer and use it in GitHub Desktop.
I used to always call a setListener method on my fragment after it was instantiated, but recently this is how I've started attaching my fragment's listener. I like it because it doesn't require the client of the fragment to remember to set the listener, and throws a runtime exception if they don't implement the listener.
This file contains 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
private CategoryFragmentListener mListener = sCategoryListener; | |
private static CategoryFragmentListener sCategoryListener = new CategoryFragmentListener() { | |
@Override | |
public void onLeafCategoryChosen() { | |
} | |
}; | |
@Override | |
public void onAttach(Activity activity) { | |
super.onAttach(activity); | |
mListener = (CategoryFragmentListener) activity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment