简体   繁体   English

使用AsyncTask进行ANDROID自动完成

[英]ANDROID AutoComplete using AsyncTask

I have an AutoCompleteTextView in my layout and I want to do an API call which takes the first character entered as a parameter. 我的布局中有一个AutoCompleteTextView,我想进行一个API调用,它将第一个字符作为参数输入。 I do this API call in an AsyncTask to which I pass the first character as a parameter. 我在AsyncTask中执行此API调用,我将第一个字符作为参数传递给它。

What listener should I use on AutoCompleteTextView so that AsyncTask call happens right after the first character is inputted ? 我应该在AutoCompleteTextView上使用什么监听器,以便在输入第一个字符后立即调用AsyncTask?

Fixed this issue using addTextChangedListener. 使用addTextChangedListener修复了此问题。

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().trim().length() == 1) {
                isFileReceived = false;
                mAirport = new AsyncTaskAirport(s.toString());
                mAirport.execute((Void) null);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM