Skip to content Skip to sidebar Skip to footer

In Android, How Do I Dynamically Swap A Fragment By Button Click Or Other Event?

I'm stuck at a sore point: fragments. Here's a reference of the layout I'm trying to swap out fragment C with fragment D upon button click. Fragment A and B needs to stay without

Solution 1:

There is a call within FragmentTransaction to replace the fragment in the container. You just need to have a designated container hold the place where c and d will go, and then upon button click do something like: getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "FragD");

Solution 2:

Android Fragment API let you to make some transactions in it like add new one , delete and replace one with another one that's will help you to build flexible UI design based on your device size ,

and here some guide for you :

http://developer.android.com/training/basics/fragments/fragment-ui.html

http://www.cs.dartmouth.edu/~campbell/cs65/lecture09/lecture09.html

http://android-er.blogspot.com/2013/04/replace-fragment.html

and if you facing any problem in code tell me to discuss in it

Post a Comment for "In Android, How Do I Dynamically Swap A Fragment By Button Click Or Other Event?"