Changes

Jump to: navigation, search

Using Fragments in Android Studio - An Example

1 byte added, 19:28, 7 May 2014
Making the Activity Talk to the Text Fragment =
With the code changes as they currently stand, the toolbar fragment will detect when the button is clicked by the user and call a method on the activity passing through the content of the EditText field and the current setting of the SeekBar view. It is now the job of the activity to communicate with the Text Fragment and to pass along these values so that the fragment can update the TextView object accordingly.
== Making the Activity Talk to the Text Fragment ==
As outlined in [[An Introduction to Using Fragments in Android Studio]], an activity can communicate with a fragment by obtaining a reference to the fragment class instance and then calling public methods on the object. As such, within the TextFragment class we will now implement a public method named changeTextProperties() which takes as arguments an integer for the font size and a string for the new text to be displayed. The method will then use these values to modify the TextView object. Within the Android Studio editing panel, locate and modify the TextFragment.java file to add this new method and to add code to the onCreateView() method to obtain the ID of the TextView object:

Navigation menu