Skip to content

Instantly share code, notes, and snippets.

@jamesmartins
Created August 25, 2015 19:54
Show Gist options
  • Save jamesmartins/3b9f9374f9b3d1ff9eab to your computer and use it in GitHub Desktop.
Save jamesmartins/3b9f9374f9b3d1ff9eab to your computer and use it in GitHub Desktop.
Comunication between Fragments (by MainActivity)
/* 1- Create a SubClassFragment extends from Fragment. */
public class SubClassFragment extends Fragment {
//Events
protected OnInterfaceEventChanged onInterfaceEventChanged;
/*
* Events
* */
public void setonInterfaceEventChanged(OnInterfaceEventChanged onInterfaceEventChanged) {
this.onInterfaceEventChanged = onInterfaceEventChanged;
}
/*
* Interfaces
* */
public interface OnInterfaceEventChanged {
void dispatchedEvent(String arg0, String arg1);
}
}
/* 2-Implements the interfaces on MainAcitvity */
public class MainActivity extends AppCompatActivity implements SubClassFragment.OnInterfaceEventChanged
/* 3-Using the methods of interfaces */
@Override
public void dispatchedEvent(String arg0, String arg1) {
anotherFragment.methods(arg0,arg1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment