如何创建将从远程服务器获取结果的AutoCompleteTextView?带服务器响应的AutoCompleteTextView
据我所知我需要实现ArrayAdapter,它必须向服务器发出异步请求。
如何创建将从远程服务器获取结果的AutoCompleteTextView?带服务器响应的AutoCompleteTextView
据我所知我需要实现ArrayAdapter,它必须向服务器发出异步请求。
1)你必须首先做出的AsyncTask一类,你必须做出其doInBackground()方法
2)你必须从REMOTESERVER这也是你的反应让arrayAdapter到远程服务器的连接要在doInBackground()方法
3)你成功后必须设置适配器AutoCompleteTextView
new AsyncTask<Integer, Void, arrayList>() {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(context, "downloading...", "Please wait...");
super.onPreExecute();
}
@Override
protected void onPostExecute(arrayList result) {
//make arrayAdapter from result
//set adapter to AutoCompleteTextView
progressDialog.dismiss();
super.onPostExecute(result);
}
@Override
protected arrayList doInBackground(Integer... params) {
// make connection to remote server
//retrive response from remote server
// make arrayList from response
return arrayList
}
}.execute(1);
AutoCompleteTextView
我不是为这样的动作,我曾经以为像你做得很b广告代码与...
如果您的自动完成列表来自他的网络基于您输入的每个字符,您最好创建一个垂直线性布局,其中包含一个EditText和一个ListView,并创建一个连接池。
对于每种密钥类型,检查它是否在100-130 ms内输入,以确保用户有可能等待响应并发出请求,对任何新请求,删除或使上一次请求发送失效。
一个响应安全到达,更新您的列表适配器。
对我来说工作顺利。
AutoCompleteTextview使用预先制作的列表。它使用AsyncTask本身,所以我很不好使用自己更新它使用的列表...
这阻止了用户界面。这触发了每个textChange的请求,因此UI被阻止..请发布解决方案 – 2012-06-20 15:14:25
这种方式是否会在android4中工作? – Akilan 2012-07-18 07:32:34