Is it possible to have two different constructors for the same Fragment
?
Here's my case : I have Fragment_A
and Fragment_B
which are almost identically, except one gets an Integer and the other a String.
Can I have something like this :
public static VideoListFragment newInstanceA(String filterString) {
VideoListFragment myFragment = new VideoListFragment();
Bundle args = new Bundle();
args.putString(FILTER, filterString);
myFragment.setArguments(args);
return myFragment;
}
public static VideoListFragment newInstanceB(String subjectId) {
VideoListFragment myFragment = new VideoListFragment();
Bundle args = new Bundle();
args.putString(POSITION, subjectId);
myFragment.setArguments(args);
return myFragment;
}
If this is possible then how am I going to get in onCreate()
the argument ? I have somehow to check if getArguments()` contains FILTER String or POSITION Integer.