Android Studio getting “Must implement OnFragmentInteractionListener”

前端 未结 3 1709
天涯浪人
天涯浪人 2021-02-19 10:52

I\'m getting a throw that says \"Must implement OnFragmentInteractionListener, and I already have it...

I\'ve looked at every question asked here, and no one helped me.<

3条回答
  •  执念已碎
    2021-02-19 11:10

    Here is why the above solutions eliminate the error. The if statement inside the overriden onAttach method of FragmentCamera.java is checking if the fragment's parent activity implements the OnFragmentInteractionListener interface, which is defined inside FragmentCamera.java. The corresponding else statement throws an error if the parent activity does not implement the interface. The interface is useful but not necessary.

    By the way, onAttach is the fragment's first lifecycle method, and it is "called once the fragment is associated with its activity". Its deprecated version is: onAttach(Activity). Its new version is: onAttach(Context). Hope this helps someone.

提交回复
热议问题