setText() - How to Set the Text on a Button, in any method, in Java


1. Add a Button to your xml file.

2. Find a button using ID, named myButton, declared as a class variable. 

3. You can now add the setText line of code to any method. For example, in an onClickButton method.

  public void onClickButton(View v) { //needs import android.view.View;

       myButton.setText("This is the new text!");
 }

4. Compile and run!