我在按钮点击时有替换片段的代码,但是这可以替换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,谢谢。
答案 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();
}