Skip to content Skip to sidebar Skip to footer

Change Fragment View

I have an app with fragments. It works fine. One of the fragments has a button, and when pressed I want to change the view. public class BikeRecap extends Fragment { public static

Solution 1:

You can't have a fragment inside a fragment.

Try this code:

FragmentManager fragmentManager2 = getFragmentManager();
FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
DetailFragment fragment2 = new DetailFragment();
fragmentTransaction2.addToBackStack("abc");
fragmentTransaction2.hide(BikeRecap.this);
fragmentTransaction2.add(android.R.id.content, fragment2);
fragmentTransaction2.commit();

Solution 2:

I think you can, pretty easily, do what you are trying to do. If OpenNewView is implemented by the Activity, instead of by the fragment:

getActivity().openNewView(...)

... then the Activity can easily replace the current fragment with a new one, using the standard transaction mechanism.

G. Blake Meike Marakana

Programming Android 2ed is now in stores: http://bit.ly/programmingandroid


Post a Comment for "Change Fragment View"