How to start a Fragment/Activity within Fragment?
16,221
Solution 1
Try:
getFragmentManager()
.beginTransaction()
.replace(containerViewId, newFragment)
.addToBackStack(null) // enables back key
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) // if you need transition
.commit();
Solution 2
You should to use FragmentTransaction enter link description here.
Like this
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.yourFragment, YourFragmentWithImageClass.getInstance());
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.commit();
in your Activity
Author by
DroidLearner
Updated on June 04, 2022Comments
-
DroidLearner almost 2 years
I have a button in
Fragment
. WhenButton
is clicked it has to Open newFragment/Activity
withinFragment
. I have written code usingIntent
,Intent i = new Intent(); i.setClass(getActivity(), UpdateProfile.class); startActivity(i);
but its opening in new activity like in below image.My requirement is in Picture 1. Can someone suggest me how to do it?
EDIT: As suggested by rai and ADK, its working fine but new fragment overlays on old fragment. See the below image. "Change Password"(
TextView
) is New Fragment which overlays on existing fragment.