How to communicate between Android Activity and Fragment

In this fragment communication tutorial, We learn how to do communication between Android Activity and Fragment.
In this tutorial we create one fragment MyFragment which extends Fragment , in this fragment we create on Interface named FragmentInteractionListener this interface contain one method onRadioButtonSelected() , this method delegate choice made by user in Fragment to Activity.
Our MainActivity implements FragmentInteractionListener show when user make choice, we can get user choice in MainActivity.
In MainActivity we save user's choice and when you reopen fragment again then we can set user
previous choice.


Let's show the Code.


MainActivity.java
activity_main.xml
MyFragment.java.
fragment_layout.xml

Leave you comments And Let us know you thoughts about this tutorial.
-Trendy Programmer

No comments:

Post a Comment