Open Fragment from another Fragment?

后端 未结 1 1121
梦毁少年i
梦毁少年i 2020-12-12 05:07

is it possible to open a fragment B from fragment A by tapping on a button in fragment A? Both fragments are part of a main FragmentActivity. How can I handle that?

相关标签:
1条回答
  • 2020-12-12 05:33

    Add below code to onClick():

    public void onClick(View v) {
                Fragment fragment = new projectInformationFragment();
                FragmentTransaction transaction = 
                getActivity().getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.nav_host_fragment, fragment);
                transaction.addToBackStack(null);
                transaction.commit();
            }
    
    0 讨论(0)
提交回复
热议问题