如何使用按钮从子片段返回父活动?

时间:2017-06-08 08:00:07

标签: java android

我从堆栈中看到许多回答使用po,但它们对我没用。

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_new_appointment, container, false);
    Toolbar toolbar = (Toolbar)rootView.findViewById(R.id.toolbar_new_appointment);
    ((DoctorCardActivity)getActivity()).setSupportActionBar(toolbar);

    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    Log.i("OROLA","IN ON CLICK");

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("OROLA","IN ON CLICK");
            getActivity().onBackPressed();

        }
    });
    getActionBar().setTitle("Select Slot");

我的活动就是这个

    @Override
    public void onBackPressed() {
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        } else {
            super.onBackPressed();
        }
    }

0 个答案:

没有答案