Houston, We Have Input! 54/100 Days of Code
I figured out how to get input using an EditText layout!
I added an OnEditorActionListener to the EditText layout in the Search Activity. Now the app can utilize the input entered by users. You can find a video at the bottom of the page and a link to the source code here.
My first step was to update the xml layout for the Search Activity. I added the android:imeOptions attribute and set the value to actionDone. In the Search Activity, I invoked the setOnEditorActionListener() method on the editText object and overrode the onEditorAction() method. I added logic which adds another String to the ArrayAdapter object depending on the content of the EditText.
The android:imeOptions attribute configures the enter key on the bottom right of the keyboard when it is open. By setting it to actionDone, a key appears which closes the keyboard when pressed.
Overriding the onEditorAction() method allowed me to configure what happens when a user presses the enter key on the keyboard. In this case, if the user types the text “Dave”, pressing the enter key will append the String “Chappelle” to the list of addresses on screen.
This was pretty straightforward. Not too different from setting up an onClickListener. The only difference I see is that I need to configure what happens based on the action performed when the user presses enter on the keyboard.
I’m going to stop here for a while. I want to update the way the ArrayAdapter for the addresses is used. Instead of containing a list of Strings, I want to use the objects themselves. This will make it easier to update the list programmatically.
For more on this, watch the YouTube video below. For the source code click here
Join the mailing list to see updates like this every week!
Coding Fanatic