1

I have this Android project, where from the MainActivity I call some Fragments.

But without including FragmentName.OnFragmentInteractionListeners in the MainActivity I am not able to go to those Fragments.

Public class MainActivity extends AppCompatActivity
    implements DirectoryFragment.OnFragmentInteractionListener,
    HireDriverFragment.OnFragmentInteractionListener {

What I am worrying about is that I should do this for each Fragment.

If I don't add those Listeners I will get these errors when I try to initiate those Fragments.

must implement OnFragmentInteractionListener

If need more code to provide a better solution I am ready to provide.

hata
  • 11,633
  • 6
  • 46
  • 69
JackyBoi
  • 2,695
  • 12
  • 42
  • 74

1 Answers1

0

What I am worried is that should I do this for every single fragment?

You could create an Interface as Communicating Android Document says, and then you'll have to add the onFragmentInteractionListener on your Fragments.

Also take a look on this Question there are many answers that might help you :)

Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148