To get the text from an EditText widget in Android, you can use the getText()
method. This method returns an instance of the Editable
class, which is a subtype of CharSequence
. Here's an example of how you can use it in an Activity:
EditText editText = (EditText) findViewById(R.id.edit_text); String text = editText.getText().toString();
In this example, edit_text
is the ID of the EditText widget in the layout file. The getText()
method returns an Editable
object, which you can then convert to a String
using the toString()
method.
You can also use the getText()
method to get the text as a CharSequence
instead of a String
, like this:
CharSequence text = editText.getText();
Note that the getText()
method returns the current text in the EditText widget, not the hint text that is displayed when the widget is empty. To get the hint text, you can use the getHint()
method.