31.8 Making the Activity Talk to the Text Fragment
As outlined in “An Introduction to Android Fragments”, 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:
package com.ebookfrenzy.fragmentexample;
.
.
public class TextFragment extends Fragment {
.
.
public void changeTextProperties(int fontsize, String text)
{
binding.textView2.setTextSize(fontsize);
&...