Below is a working code to add a fragment e.g 3 times to a vertical LinearLayout (xNumberLinear). You can change number 3 with any other number or take a number from a spinner!
for (int i = 0; i < 3; i++) {
LinearLayout linearDummy = new LinearLayout(getActivity());
linearDummy.setOrientation(LinearLayout.VERTICAL);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Toast.makeText(getActivity(), "This function works on newer versions of android", Toast.LENGTH_LONG).show();
} else {
linearDummy.setId(View.generateViewId());
}
fragmentManager.beginTransaction().add(linearDummy.getId(), new SomeFragment(),"someTag1").commit();
xNumberLinear.addView(linearDummy);
}