这是调用片段的正确方法吗?

Is this the right way to call Fragments?

我有这个 Android 项目,我从 MainActivity 调用一些 Fragments.

但如果 MainActivity 中没有包含 FragmentName.OnFragmentInteractionListeners,我将无法访问那些 Fragments

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

我担心的是我应该为每个 Fragment.

做这个

如果我不添加这些 Listeners,我将在尝试启动这些 Fragments 时遇到这些错误。

must implement OnFragmentInteractionListener

如果需要更多代码来提供更好的解决方案,我随时准备提供。

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

您可以按照 Communicating Android Document 的说明创建一个 Interface,然后您必须在 Fragments.

上添加 onFragmentInteractionListener

也看看这个 Question 有很多答案可能对你有帮助:)