Android AutoCompleteTextView : Perform a AsyncTask call only once on TextChange
<p>I have an AutoCompleteTextView in my layout. After the user entered the first character, I'd like to do an API call, which I'm doing in an AsyncTask. I've used addTextChangedListener and I'm doing the API call on TextChanged. But the problem is that the API call is getting done each time the user makes any change to the AutoCompleteTextView. </p>

<p>But I'd want the API call to happen only once, that is after the first character is inputted. How do I achieve this ?</p>

<pre><code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_places_search);
    search_airport = (AutoCompleteTextView) findViewById(R.id.place_search);
    autocompleteadapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, airports);
    search_airport.setAdapter(autocompleteadapter);
    search_airport.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mAirport = new AsyncTaskAirport(search_airport.getEditableText().toString().substring(0, 1));
            mAirport.execute((Void) null);

        }

        @Override
        public void afterTextChanged(Editable s) {


        }
    });


}
</code></pre>