Hello, I am trying to implement an AutoCompleteTextView backed by HTTP requests. i.e., the content of the suggestion comes from a web service and is obtained by a HTTP request (for example, the symbol lookup field on Google finance).
Here's the code I wrote to initialize the autocomplete field: final AutoCompleteTextView field = (AutoCompleteTextView)findViewById(R.id.lookup_input_field); List<String> suggestions = new ArrayList<String>(); final MyAutoCompleteAdapter adapter = new MyAutoCompleteAdapter(this, R.layout.auto_complete_dropdown, suggestions); field.setAdapter(adapter); field.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { String newValue = field.getEditableText().toString(); adapter.valueChanged(field, newValue); } }); And here's the valueChanged method of the adapter. The suggestion retrieval is done in a thread to ensure responsive UI. public void valueChanged(final AutoCompleteTextView view, final String value) { final Handler handler = new Handler() { public void handleMessage(Message msg) { clear(); List<String> suggestions = (List<String>)msg.obj; for (String suggestion : suggestions) { add(suggestion); } notifyDataSetChanged(); } }; new Thread() { public void run() { List<String> suggestions = SearchHelper.search(value); if (suggestions.size() > 0) { Message msg = new Message(); msg.obj = suggestions; handler.sendMessage(msg); } } }.start(); } Here's my problems: a) The suggestion dropdown doesn't always show up on each keystroke, even though I know the SearchHelper has successfully requested and returned suggestions based on user input. b) When I select an item, the onTextChanged seems to be invoked again and the suggestion dropdown shows up again. Sorry if someone has discussed this issue but I wasn't able to find any examples for my scenario. Thanks! Ken -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en