// Get a reference to an EditText object EditText editText = findViewById(R.id.edit_text); // Append text to the EditText object editText.append("Hello World!");
// Get references to the EditText and Button objects EditText editText = findViewById(R.id.edit_text); Button button = findViewById(R.id.button); // Set a click listener for the button button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Append text to the EditText object editText.append("Button clicked\n"); } });In both examples, the append() method is called on an EditText object to append text to it. The first example appends text immediately, while the second example appends text in response to a button click. The android.widget package contains the EditText class.