Created
August 25, 2015 19:54
-
-
Save jamesmartins/3b9f9374f9b3d1ff9eab to your computer and use it in GitHub Desktop.
Comunication between Fragments (by MainActivity)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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