Can an Activity access a Fragment to know if a button has been pressed?

后端 未结 4 744
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 03:28

The Objective: I\'m trying to make a notepad application. What my app does is, a button is pressed to create a new note. This pops up a fragment in which th

4条回答
  •  感情败类
    2020-12-22 03:58

    Just make your activity implement View.OnClickListener and on your fragment set your activity as onClickListener of your button.

    your fragment:

       @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            myButton.setOnclickListener((MyActivity)getActivity));
        }
    

提交回复
热议问题