Create a Fragment | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7503473-your-second-kotlin-android-app/lessons/32

After following the tutorial step by step, I’ve created an empty fragment but the Kotlin file is different, first of all there is no listener variable and when I try to create one manually it doesn’t compile, i’ve tried autocomplete to see if there is another package name I’m not using but that doesn’t seem to be the case.
furthermore the other overwritten that depends on the listener methods don’t exist either. Is there something I’m missing?

1 Like

When you try to compile, what compile error are you receiving?

Unresolved reference: OnFragmentInteractionListener

1 Like

I am having the same issue - I am using Android Studio 3.6.2. The OnFragmentInteractionLIstener is not included in the project, and neither are the onAttach and onDetach methods. The OnFragmentInteractionListener is not available. Additionally, when I created the project, Android Studio set up the base project using 2 fragments - FirstFragment and SecondFragment. It also included a navigation folder under res, with the file nav_graph.xml. In preparing the project to follow along with your tutorial, I deleted the files that were not in line with your project.

1 Like

In looking at it further, the problem starts in creating the fragment. The Configure Component screen that is displayed when adding the fragment does not have the “Include interface callbacks” checkbox option.

I manually added the OnFragmentInteractionListener, its corresponding interface, and the onAttach and onDetach methods, and made the necessary changes to bring my fragment in line with that shown in the video.

Thanks.
I’ve just now noticed the OnFragmentInteractionListener is actually defined on this file.