on change event for autocompletetextview

Put your problem here if it does not fit any of the other categories.

on change event for autocompletetextview

Postby ametim » Wed Sep 08, 2010 10:36 am

Hallo everybody,

I use in my application an autocompletetextview field and would like to implement following functionality:
- There is an entry (the last one) in the adapter which should always contain of "user input:" + vartext. The vartext is the text typed by user in autocompletetextview field.

Is there any change listener for autocompletetextview?

I tried to use addTextChangedListener, TextWatcher and onTextChanged, but it seems to be called only once.

Did I do something wrong?! Here is my code:

Code: Select all
public class HelloListView extends Activity
   List<String> countryList = null;   
   AutoCompleteTextView textView = null;   
   ArrayAdapter adapter = null;
   static String[] COUNTRIES = new String[]
        "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
        "Yemen", "Yugoslavia", "Zambia", "Zimbabwe", ""
   /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
        countryList = Arrays.asList(COUNTRIES);

        textView = (AutoCompleteTextView) findViewById(R.id.edit);
        adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, countryList);
        textView.addTextChangedListener(new TextWatcher()
         public void onTextChanged(CharSequence s, int start, int before, int count)
            countryList.set(countryList.size()-1, "User input:" + textView.getText());
         public void beforeTextChanged(CharSequence s, int start, int count,
               int after)
         public void afterTextChanged(Editable s)

I saw already [url]this topic[/url] but they suggest to clear adapter and to fill it again. It's not really thing I want to have.

Thank you in advance,

Posts: 5
Joined: Wed Jun 30, 2010 1:51 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 4 guests