Android fragmentation builder that takes arguments


I have the Class MyFragment which extends Fragment.

MyFragment contains different widgets(views) which the user can edit. The initial value of each widget is calculated when the MyFragment fragment is constructed.

And then the user can edit the values afterwards.

The obvious implementation is to have the constructor: MyFragment(String value1,int value2) { } which set the initial widget values and then I just need to implement onSaveInstanceState to persist the value of each widget, so they can be restored by onCreateView.

Easy but there is one problem. I can't add a constructor to MyFragment which take arguments because eclipse/adt will not allow that. Is it safe to just add @SuppressLint("ValidFragment") to the constructor or is there a better way to handle this?

Or use this where foo is a member variable

public YourFragment newInstance (Foo foo) {
    YourFragment frag = new YourFragment ();
     frag.setFoo (foo);
     return frag;

public void setFoo (Foo foo) { = foo;