单击按钮如何替换FragmentActivity?

时间:2016-02-16 10:38:08

标签: java android android-fragments android-fragmentactivity

我在按钮点击时有替换片段的代码,但是这可以替换FragmentActivity吗?

我有替换片段的代码

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();
    }

请建议我使用FragmentActivity,谢谢。

2 个答案:

答案 0 :(得分:0)

Intent intent = new Intent(getActivity(), OtherActivity.class);
getActivity().startActivity(intent);

答案 1 :(得分:0)

试试这个

 ExampleFragment fragment= new ExampleFragment();

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

    }