public class MainActivity extends AppCompatActivity {

    /**

    * Show a message in a TextView.

    *

    * @param newMessage The message.

    * @param resourceId The resource id of the TextView.

    * @return The TextView's previous message.

    */

    private String showMessage(String newMessage, int resourceId) {

        // Create a local variable named textView

        // that refers to a TextView object created in the file activity_main.xml.

        TextView textView = (TextView) findViewById(resourceId);

        // Make a copy of the TextView’s message,

        // since the new message will wipe it out.

        // Must convert the CharSequence returned by getText to a String.

        String oldMessage = textView.getText().toString();

        // Display the new message in the Text View, wiping out the old one.

        textView.setText(newMessage);

        // Return the previous message, in case anyone is still interested in it.

        return oldMessage;

    }

}