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

前端 未结 13 905
失恋的感觉
失恋的感觉 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:57

    In your Fragments onCreateView(...) you can remove a view by calling container.removeView(view);. So if you want to remove the fragment, then view should be the return value of onCreateView,

    for example

        public View onCreateView(...){
            final View view = inflater.inflate(R.layout.your_fragments_layout,container,false);
            //Do something
            finishButton.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v){
                    container.removeView(view);
                }
            });
            return view;
        }
    

提交回复
热议问题