AutoCompleteTextView gives suggestions to a user based on what is being typed. I have used this in CashLog and MoneyLog to make it easy to re-use existing descriptions for new log entries. Start by adding a AutoCompleteTextView to your layout.This is the EditText the user will type into. Suggestions will appear below the input field, like a dropdown box. The suggestions are fed to the UI component through an Adapter .Which kind of Adapter you need depends on the source of your suggestions. I have used a SimpleCursorAdapter to get the data from the database because that is where the descriptions of older log entries are stored.This is what my query looks like: pattern = "%" + pattern + "%"; %pattern% and LIKE make the query return all results which are similar to the supplied pattern.To make the UI call the query after each modification of the value of the EditText, a FilterQueryProvider must be set to it.This can be implemented as an anonymous inner class. A suggested value could possibly not conform to the input rules of the EditText. AutoCompleteTextView.Validator can be used to check this and fix it if necessary.MultiAutoCompleteTextView allows the user to enter several values into a single EditText, each of the values will be autocompleted while typing. |
Development > Tutorials >