autocomplete in android not working with dynamic data
<p>I am facing problem with auto complete in android. Instead of hard coding data in Activity itself, I tried to read the data dynamically from other application on every key press which is matched. Please find below my program and suggest me where I am wrong.</p>

<p>Note: at the first time key press, the results are getting populated. After that if I clear the entered text and enter different character, the results are not getting shown in the auto complete drop down box. I am getting from other application on every key press but not getting populated in auto complete drop down box.</p>

<p>I tried with textView.showDropDown(); and adapter.setNotifyOnChange(true); options. But no use.</p>

<pre><code>package com.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class HelloAutoCompleteActivity extends Activity {
List countries = new ArrayList();
    String url = ""; //some application url
AutoCompleteTextView textView;
ArrayAdapter&lt;String&gt; adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
    textView.addTextChangedListener(new CostomTextWatcher());
    textView.setThreshold(1);
    adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, countries);
    textView.setAdapter(adapter);
}

private class CostomTextWatcher implements TextWatcher {

    @Override
    public void afterTextChanged(Editable s) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        if (s.length() &gt; 0) {
            countries.clear();
            String readTwitterFeed = readFeed(s.toString());
            System.out.println(readTwitterFeed);
            try {
                JSONObject menuObject = new JSONObject(readTwitterFeed);
                JSONArray menuitemArray = menuObject
                        .getJSONArray("objectNameList");
                for (int i = 0; i &lt; menuitemArray.length(); i++) {
                    System.out.println(menuitemArray.get(i));
                    countries.add(menuitemArray.get(i).toString());
                }
                // adapter.notifyDataSetChanged();
                // adapter.setNotifyOnChange(true);
                // textView.setAdapter(adapter);
                // textView.setThreshold(1);
                // textView.setAdapter(adapter);
                // textView.showDropDown();
                // adapter.setNotifyOnChange(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

public String readFeed(String val) {

    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(
            url);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            System.out.println("200");
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            System.out.println("else block");
            Log.e(HelloAutoCompleteActivity.class.toString(),
                    "Failed to download file");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
</code></pre>

<p>}</p>
