0

I have code of replace fragment on button click, but is this possible to replace FragmentActivity??

I have code of replace fragment

public void OnClick()
    {
        Fragment frag = new TMSAccountFragment(CurrentViewModel);

        FragmentTransaction ft = FragmentManager.BeginTransaction();
        ft.Replace(Resource.Id.sample_content_fragment, frag);
        ft.AddToBackStack(null);
        ft.Commit();
    }

Please suggest me for FragmentActivity, thanks.

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
  • 1
    To replace FragmentActivity is not feasible. Try to understand difference between fragment and fragmentActivity. Check this link, http://stackoverflow.com/questions/10609268/difference-between-fragment-and-fragmentactivity – Ronak Joshi Feb 16 '16 at 10:41
  • 1
    NOTE: **FragmentActivity is an Activity, not a Fragment**. Start an activity using Intent. Use FragmentTransaction and FragmentManager to load/add and unload/remove or replace a fragment – kishorepatel Feb 16 '16 at 11:40

2 Answers2

0
Intent intent = new Intent(getActivity(), OtherActivity.class);
getActivity().startActivity(intent);
Nivedh
  • 971
  • 1
  • 8
  • 19
0

try this

 ExampleFragment fragment= new ExampleFragment();

if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.homemain, fragment);
        fragmentTransaction.commit();

    }
Moorthy
  • 723
  • 1
  • 6
  • 20
  • by using above code you can only replace fragment not fragment activity To start fragment activity you have to use startactivity(new Intent(...); – Moorthy Feb 16 '16 at 13:37