Dynamic AutocompleteTextView with ArrayAdapter and TextWatcher

I am trying to update a dynamic use list of AutocompleteTextView and ArrayAdapter. To update this view, I use TextWatcher to track any changes that may occur in AutocompleteTextView.

The problem is that the list is not updated at all, and I cannot understand why. I was looking for something similar on the Internet, and I found a couple of different approaches, but still I can’t understand why this one, which should be the simplest, does not work. Any explanation would be greatly appreciated.

Target AVD: Google API Level 10, Android 2.3.3

Here is the simplified code:

public class AutocompleteActivity extends Activity implements TextWatcher {
    ArrayAdapter<String> adapter = null;
    AutoCompleteTextView acTextView = null;
    ArrayList<String> addresses = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.autocompleteview);

        acTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_address);
        adapter = new ArrayAdapter<String>(this, R.layout.listitem, addresses);
        adapter.setNotifyOnChange(true);
        acTextView.addTextChangedListener(this);
        acTextView.setAdapter(adapter);
    }

    @Override
    public void onTextChanged(CharSequence text, int start, int before, int after) {
        try {
            adapter.add("test");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
+5
1

TextWatcher AutoCompleteTextView, .

AutoCompleteTextView, , AutoCompleteTextView TextWatcher, "MyWatcher". - AutoCompleteTextView .

+3

All Articles