我在“活动”中有片段。片段具有按钮。如果我单击按钮,则片段必须关闭。我是怎么做到的?

public class ItemFragment extends Fragment{

    private ImageView btnApply;
    private ClickButton clickButton = new ClickButton();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.item_info, container, false);
        btnApply = (ImageView) rootView.findViewById(R.id.btnSendItem);
        btnApply.setOnClickListener(clickButton);
        return rootView;
    }

    private class ClickButton implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            if (R.id.btnSendItem == v.getId()) {
                Toast.makeText(getActivity(),"CLOSE",Toast.LENGTH_LONG).show();
                return;
            }
        }
    }
}

最佳答案

没有诸如关闭片段之类的东西,但是您可以从堆栈中删除该片段。要弹出片段,请使用以下内部按钮单击监听器

getActivity().getFragmentManager().beginTransaction().remove(this).commit();

关于android - 如何关闭 fragment ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29094423/

10-09 01:52