I have an activity which instantiates and populates a Fragment through a adopter class. I want to pass values/objects to this Fragment adopter class so that i can dictate la
To pass argument to your fragment, it's recommended to create a public static method to instanciate your fragment like :
public static MyFragment newInstance(String firstArg) {
MyFragment f = new MyFragment ();
Bundle args = new Bundle();
args.putString("ARG1", firstArg);
f.setArguments(args);
return f;
}
And then retrieve your args in onCreateView()
method like :
String arg = getArguments().getString("ARG1");
Use the static method to instanciate a new fragment with your arguments in other fragment or activities like :
MyFragment f = MyFragment.newInstance(myArg);