如何創建將從遠程服務器獲取結果的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