I have an activity which implements this method:
public void pushFragment(MyFragment fragment) {
stack.add(fragment);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.main_frame_layout, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
setTitle(fragment.getTitle(this));
}
In a fragment, I have a listview with this onItemClickListener:
getAppActivity().pushFragment(anotherFragment);
the AnotherFragment onCreateView method:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
LayoutTransition t = new LayoutTransition();
container.setLayoutTransition(t);
View rootView = inflater.inflate(R.layout.another_layout, container, false);
final ViewGroup vg = (ViewGroup)rootView.findViewById(R.id.avatar_image_layout);
vg.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
// Stuff
return rootView;
}
On API level >= 19 everything works. On API 18 and 17 (I didn't test on API 16), the first time I click on the listview item it works. Then I go back and click another time on the item. This time the fragment is created, onActivityCreated and onCreateView etc are called, but the fragment isn't displayed.
EDIT 1: Commenting random stuff, I've found out that the problem is:
LayoutTransition t = new LayoutTransition();
container.setLayoutTransition(t);
commenting these two lines solves the problem, but I don't know why and I loose the animation...