How to close the current fragment by using Button like the back button?

前端 未结 13 883
失恋的感觉
失恋的感觉 2020-12-07 14:02

I have try to close the current fragment by using Imagebutton.

I am in Fragment-A and it will turn to the Fragment-B when I click the button.

And when I clic

13条回答
  •  旧巷少年郎
    2020-12-07 14:39

    Try this:

    ft.addToBackStack(null);   // ft is FragmentTransaction
    

    So, when you press back-key, the current activity (which holds multiple fragments) will load previous fragment rather than finishing itself.

提交回复
热议问题