Issue With Fragment Transaction And Passing Values To Fragment?
im having some troubles with FragmentTransaction and passing values from activityA to fragmentA. The problem i think i am having is that i make 2 new FragmentA()instances and this
Solution 1:
There is a different approach to use to pass data from activity to bundle. Make a method newInstance(Objects you wanna pass as parameters) inside fragment, if you type in AndroidStudio newInstance inside Fragment class it will automatically suggest the implementation for you, if not it will look like this:
publicstatic TodoFragment newInstance(data to pass){
Bundleargs=newBundle();
//then you put into args the data you wann pass with args specific key,value method
fragment.setArguments(args);
return fragment;
}
In the activity instead of new TodoFragment(), you use TodoFragment.newInstance(data to pass); To retrieve the passed data you use getArguments(), in Fragment's onCreate()
Post a Comment for "Issue With Fragment Transaction And Passing Values To Fragment?"