Created
May 24, 2012 19:20
-
-
Save alexjlockwood/2783675 to your computer and use it in GitHub Desktop.
newInstance() fragment instantiation #2
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 MyFragment { | |
/** | |
* Make the default constructor private to prevent direct | |
* instantiation. Now all instances of this class must be | |
* instantiated with a call to newInstance(). | |
*/ | |
private MyFragment() { } | |
/** | |
* Static factory method that takes an int parameter, | |
* initializes the fragment's arguments, and returns the | |
* new fragment to the client. | |
*/ | |
public static MyFragment newInstance(int index) { | |
MyFragment f = new MyFragment(); | |
Bundle args = new Bundle(); | |
args.putInt("index", index); | |
f.setArguments(args); | |
return f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment