Android dynamic auto-complete - minor fix - code attached
<p>I am trying to implement a dynamic autocomplete widget in android. I am done with the major functionalities and the autocompletion implemented is for youtube video search.</p>

<p>When I start typing a letter or two, the auto-completion is not working. But when I type three letters or more it works prfect. It also works when I type two letters and hit a backspace. I do not know what is wrong with the code. </p>

<p>I have uploaded the code <a href="http://www.4shared.com/file/4xuD7jXy/YoutubeAutoComplete.html" rel="nofollow">here</a></p>

<p>Experts, kindly guide me. I would be obliged if you can point out where I have gone wrong with the code.</p>

<p>Any help in this regard is well appreciated.</p>

<p>Looking forward,
Regards,
Rony</p>

<pre><code>import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;

public class YoutubeAutoComplete extends Activity {
Youtube yt = new Youtube();
CustomAutoComplete myAutoComplete;
ArrayAdapter&lt;String&gt; adapter;
private JSONArray js;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    myAutoComplete = (CustomAutoComplete) findViewById(R.id.autocomplete);
    adapter = new ArrayAdapter&lt;String&gt;(this,
            android.R.layout.simple_dropdown_item_1line);
    myAutoComplete.addTextChangedListener(textWatcher);
    myAutoComplete.setAdapter(adapter);
    adapter.notifyDataSetChanged();
}

TextWatcher textWatcher = new TextWatcher() {

    public void onTextChanged(final CharSequence s, int start, int before,
            int count) {

        Thread t = new Thread() {

            public void run() {
                try {
                    js = yt.GetSuggestions(s.toString()).getJSONArray(1);
                    messageHandler.sendEmptyMessage(0);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        };
        t.start();
    }

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

    }

    public void afterTextChanged(Editable s) {
    }
};

private Handler messageHandler = new Handler() {
    public void handleMessage(Message msg) {
        adapter.clear();
        for (int i = 0; i &lt; js.length(); i++) {
            try {
                adapter.add(js.getJSONArray(i).getString(0));
                System.out.println(js.getJSONArray(i).getString(0));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        adapter.notifyDataSetChanged();
    }
};

}
</code></pre>
