How To Set Text In An EditText

user555910 picture user555910 · Jan 4, 2011 · Viewed 286.7k times · Source

How can I set the text of an EditText?

Answer

Kevin Coppock picture Kevin Coppock · Jan 4, 2011

If you check the docs for EditText, you'll find a setText() method. It takes in a String and a TextView.BufferType. For example:

EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("This sets the text.", TextView.BufferType.EDITABLE);

It also inherits TextView's setText(CharSequence) and setText(int) methods, so you can set it just like a regular TextView:

editText.setText("Hello world!");
editText.setText(R.string.hello_world);