Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Create two separate interfaces, one for one Fragment, then another for the other Fragment. Give them separate names like onFragmentAListener and on FragmentBListener, as well as change the onAttach's to correspond to the correct interfaces. Then implement both interfaces with the main activity. </p> <p>Each fragment will look something like this:</p> <pre><code>public class FragmentA extends Fragment { private FragmentAListener mCallback; public interface FragmentAListener { onFragmentADoSomething(); } @Override public void onAttach (Activity activity){ super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (FragmentAListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement FragmentAListener"); } } //where ever you need to do the callback... mCallback.onFragmentADoSomething(); } </code></pre> <p>In the main activity, do something like this:</p> <pre><code>public class Main_Activity extends FragmentActivity implements FragmentA.FragmentAListener, FragmentB.FragmentBListener{ @Override public void someEvent(int FixtureNumber, int R_value, int G_value, int B_value) { // whatever you have it doing here } @Override public void onFragmentAListener (int FixtureNumber, int R_value, int G_value, int B_value) { someEvent(...); } @Override public void onFragmentBListener (int FixtureNumber, int R_value, int G_value, int B_value) { someEvent(...); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload