Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just overwrite <code>onBackPressed()</code> in your activity and your fragment and do your required calls there.</p> <p>More to callbacks / communication with other fragments can be found here:</p> <p><a href="http://developer.android.com/training/basics/fragments/communicating.html" rel="nofollow">Communicating with Other Fragments</a></p> <pre><code>public class FragmentA extends Fragment { public void updateMyself(String updateValue){ Log.v("update", "weeee Fragment B updated me with" + updateValue); } } public class FragmentB extends Fragment { public Interface FragmentBCallBackInterface { public void update(String updateValue); } private FragmentBCallBackInterface mCallback; @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (FragmentBCallBackInterface) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement FragmentBCallBackInterface"); } //As an example we do an update here - normally you wouln't call the method until your user performs an onclick or something letsUpateTheOtherFragment(); } private void letsUpateTheOtherFragment(){ mCallback.update("This is an update!); } } public class MyActivity extends Activity implements FragmentInterfaceB { @Override public void update(String updateValue){ FragmentA fragmentA = (FragmentA) getSupportFragmentManager().findFragmentById(R.id.article_fragment); if (fragmentA != null) { fragmentA.updateMyself(updateValue); } else { //replace the fragment... bla bla check example for this code } } } </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