As described in Android website, EditText is a thin veneer over TextView that configures itself to be editable. We use edit text when we want to input some text values.
We have been using EditText in our previous examples. In this section, we will be creating another example just to refresh our familiarity on the EditText component.
In this example, we display the EditText component and let the user type some text values on the field. The typed text will then be displayed back to the user through a Toast message. Below are the steps in creating the sample program.
Create a project named HelloEditText. The project structure will look like this:
In the layout file named activity_main.xml, add the EditText component as follow:
Open the MainActivity.java source code and add event handling. We add a key listener so that when the user presses the Enter key from the keyboard the content of the EditText is displayed back to the user.
The classes used in our program uses the following:
Run the program. Try typing any text on the EditText area and press Enter. You will notice that the content of the EditText is displayed as a message.