2

enter image description here

I have a button in Fragment. When Button is clicked it has to Open new Fragment/Activity within Fragment. I have written code using Intent, Intent i = new Intent(); i.setClass(getActivity(), UpdateProfile.class); startActivity(i); but its opening in new activity like in below image. enter image description here

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.

enter image description here

4

2 回答 2

3

尝试:

getFragmentManager()
    .beginTransaction()
    .replace(containerViewId, newFragment)
    .addToBackStack(null) // enables back key
    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) // if you need transition
    .commit();
于 2013-04-12T11:00:24.303 回答
1

您应该使用 FragmentTransaction在此处输入链接描述

像这样

        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.yourFragment, YourFragmentWithImageClass.getInstance());
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        fragmentTransaction.commit();

在您的活动中

于 2013-04-12T10:42:55.280 回答