In the first version of the Open Event Organizer App, the event organizer was required to enter his full email each time he logged out of his account and therefore it was hindering the user experience. AutoCompleteTextView with shared preferences is a solution to this problem. This feature provides an editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu. The user can choose an item to replace the content of the edit box with. It is extremely useful in enhancing user experience.
The solution we implemented was to create an autocomplete textview for the email input, store the email address of the user on a successful login in the shared preference in a set of strings to prevent duplicacy and display it in the dropdown on subsequent login attempts.
Change your TextInputLayout structure to accommodate the autocompletetextview. Remember to create a separate autocompletetextview object with the specific id of the view.
Create Utility methods to get/store the emails in the shared preferences. The set data structure has been used here so that there is no duplicacy while storing the emails in the shared preferences.
Create helper methods to add an email and retrieve the list of emails from the shared preferences to provide it to the views.
Create an autocompleteTextView object in your activity with the help of the R id from the layout and set the adapter with the set of strings retrieved from the shared preferences. You could create a custom adapter for this case too, but as far as the Open Event Orga App was concerned, using the array adapter made sense.
It is important that the user is served with the best possible experience of the application and the autocomplete text view for the email serves just that.
- Complete Code for Reference – https://github.com/fossasia/open-event-orga-app/pull/217
- Auto Complete Text View function on Android documentation – https://developer.android.com/reference/android/widget/AutoCompleteTextView.html
- Shared Preferences on Android documentation – https://developer.android.com/training/basics/data-storage/shared-preferences.html