Change View Text

After you create a view as a Java object, you can access it in your code.

Let’s start with a TextView, which is a label that displays some text.

You can change a TextViews text as follows:

This code will change the text of your label to “This app is running” as soon as the main activity starts.

All TextView and EditText views have a setText() method that changes the text being displayed.

hello.setText("This app is running.");

hello is the object name, and setText() is a method belonging to this object.

Let Android Studio do some of the work:

If you start typing “hello,” you will notice that you can just type “he” and then hit “enter” to auto-complete the name.

Then, type a period and you’ll see some methods that are available:

Now you can use up/down arrows and enter to select one of those methods.

This saves time and also gives you a quick way to check what methods an object has.