How can I provide suggestions for an AutoCompleteTextView from a column in a database table which may have some values repeated?
http://www.outofwhatbox.com/blog/2010/11/android-autocompletetextview-sqlite-and-dependent-fields/
In learning how to use AutoCompleteTextView, I ran across the above two blog articles. These are great for an introduction but don’t quite solve my problem. I want to provide the distinct values of a column from my database as the suggestions for a AutoCompleteTextView in my app. When I implement the code from the above two examples, I get repeated suggestions in my list. Trying to use the DISTINCT keyword in my query doesn’t work because CursorAdapter requires an _id field in the returned results. Since each row has its own _id, the repeated values are not eliminated.
I am considering creating a separate lookup table for the values. This has the benefit of normalizing my data as well as providing easy access to the distinct values to suggest for entries. For one of my AutoCompleteTextViews, I think this will work well because there are most likely only 4 or 5 different values that will be used. For another, it might not work as well because I’m not sure how many distinct values there will be in a large data set.
If you have a table:
And want to select only one
_idfor each distinctbaryou can use: