title: Get to a function on a fragment
body: <p>I am trying to get to a function on a fragment.</p>
  
  <p>Please look at the function msgFromTopFragment at main activity.</p>
  
  <p>The declaration of bottomFragment results in an error message – incompatible types.</p>
  
  <p>And I can’t understand why. How can I fix it?</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity
      implements TopFragment.onBtnListener{
  
      TopFragment topFragment = new TopFragment();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }//onCreate
  
      @Override
      public void msgFromTopFragment(String msg) {
          BottomFragment buttomFragment = getFragmentManager().findFragmentById(R.id.bottomFragment);
          buttomFragment.updateResult(msg);
      }//msgFromTopFragment
  }//MainActivity
  </code></pre>
  
  <p>Code for bottom fragment:</p>
  
  <pre><code>public class BottomFragment extends Fragment {
  
      TextView resultTv;
  
      public BottomFragment() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_bottom, container, false);
          resultTv = view.findViewById(R.id.resultTv);
  
          return view;
      }
  
      public void updateResult(String msg){
          resultTv.setText(msg);
      }
  }//BottomFragment
  </code></pre>