I will like to know if it's visible to use Autocomplete in such away it call some service via HTTP for fetching results and displaying it in Autocomplete list.
I have one screen with the text box and I need it to work in such away when user starts entering in that开发者_如何学Python textbox the autocomplete should get filled with the data. The data will not be hardcoded and will be retrived through http connection.
1) Create below class in your activity
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() > 0) {
//Make HTTP connection and retrives autocomplete strings from webservice
}
}
}
2) set this above class to edittext using below way
etSearch.addTextChangedListener(new CostomTextWatcher());
You have to make http connection using Background Thread
best is AsyncTask
精彩评论