How to replace a Fragment on button click of that fragment?

后端 未结 6 1041
南笙
南笙 2020-11-30 09:00

I have an activity containing multiple fragments. Activity initially have fragment and in it have two buttons. Upon clicking this button I have to replace the fragment by ne

6条回答
  •  离开以前
    2020-11-30 09:41

    You can use the following to replace a fragment on button click of that fragment:

    getFragmentManager().beginTransaction().replace(R.id.main_content, new insertFragmentNameHere()).addToBackStack(null).commit();
    

提交回复
热议问题