开发者

Autocomplete data retrived via http request (not hardcded) when user type in textbox

开发者 https://www.devze.com 2023-04-09 01:55 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号