Molto vicino a ciò che si vuole, avevo bisogno di aggiungere frammento (alla fine) a un ViewPager, e ha fatto questo:
FragmentTransaction ft = fragmentManager.beginTransaction();
new_fragment = Fragment.instantiate(activity, class_name, args);
// The below code removes old fragment and adds the new one at the end.
ft.attach(new_fragment); // <- this adds the fragment at the end
ft.detach(old_fragment); // <- this removes old fragment
// This should be what you're looking for when adding to an Activity instead of a ViewPager
ft.replace(view_id, new_fragment); // <- this is supposed to replace the fragment attached to view_id
// Or if the replace does not work, this might work:
ft.detach(old_fragment);
ft.add(view_id, new_fragment);
// Not to be forgotten: ;)
ft.commit();
Il codice di cui sopra potrebbe aver bisogno di qualche aggiustamento, forse richiede solo la sostituire la chiamata per funzionare efficacemente?
Se la chiamata di sostituzione non riesce, è comunque possibile staccare tutti i frammenti e ricollegarli nell'ordine desiderato.