I think it can help you
private AutoCompleteTextView mSearchbar;
private ArrayAdapter<String> mAutoCompleteAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
mAutoCompleteAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
mSearchbar = (AutoCompleteTextView) findViewById(R.id.searchbar);
mSearchbar.setThreshold(3);
mSearchbar.setAdapter(mAutoCompleteAdapter);
mSearchbar.addTextChangedListener(new TextWatcher() {
private boolean shouldAutoComplete = true;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
shouldAutoComplete = true;
for (int position = 0; position < mAutoCompleteAdapter.getCount(); position++) {
if (mAutoCompleteAdapter.getItem(position).equalsIgnoreCase(s.toString())) {
shouldAutoComplete = false;
break;
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (shouldAutoComplete) {
new DoAutoCompleteSearch().execute(s.toString());
}
}
}
}
private class DoAutoCompleteSearch extends AsyncTask<String, Void, ArrayList<String>> {
@Override
protected ArrayList<String> doInBackground(String... params) {
ArrayList<String> autoComplete = new ArrayList<String>();
//do autocomplete search and stuff.
return autoComplete;
}
@Override
protected void onPostExecute(ArrayList<String> result) {
mAutoCompleteAdapter.clear();
for (String s : result)
mAutoCompleteAdapter.add(s);
}
}