Question

I got a AutoCompleteTextView , but I want it to use the users' previous input instead of some strings I said it to complete, so question is: How do I do this?

Was it helpful?

Solution

AutoCompleteTextView do not propose this feature by default but you could implement it yourself.

  • storing each user input in a file or a database (I recommend to use a database)
  • retrieving those input and setting an adaptater to the AutoCompleteTextView.

Example to set an adpatater with pre defined string array from Google doc:

http://developer.android.com/reference/android/widget/AutoCompleteTextView.html

    public class CountriesActivity extends Activity {
       protected void onCreate(Bundle icicle) {
           super.onCreate(icicle);
           setContentView(R.layout.countries);

           ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                   android.R.layout.simple_dropdown_item_1line, COUNTRIES);
           AutoCompleteTextView textView = (AutoCompleteTextView)
                   findViewById(R.id.countries_list);
           textView.setAdapter(adapter);
       }

       private static final String[] COUNTRIES = new String[] {
           "Belgium", "France", "Italy", "Germany", "Spain"
       };
    }

Instead to use a fix array COUNTRIES like in the example above, use a String array retrieved from the database,

OTHER TIPS

If you want your AutoCompleteTextView to show suggestions based on some string rather than taking input from user then just call:

myAutoCompleteTextView.setText("cou", true);

and then in case drop down is not shown, call:

myAutoCompleteTextView.showDropDown();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top