2011-04-21 62 views

回答

3

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); 
+1

這阻止了用戶界面。這觸發了每個textChange的請求,因此UI被阻止..請發佈解決方案 – 2012-06-20 15:14:25

+0

這種方式是否會在android4中工作? – Akilan 2012-07-18 07:32:34

6

AutoCompleteTextView我不是爲這樣的動作,我曾經以爲像你做得很b廣告代碼與...

如果您的自動完成列表來自他的網絡基於您輸入的每個字符,您最好創建一個垂直線性佈局,其中包含一個EditText和一個ListView,並創建一個連接池。

對於每種密鑰類型,檢查它是否在100-130 ms內輸入,以確保用戶有可能等待響應併發出請求,對任何新請求,刪除或使上一次請求發送失效。

一個響應安全到達,更新您的列表適配器。

對我來說工作順利。

AutoCompleteTextview使用預先製作的列表。它使用AsyncTask本身,所以我很不好使用自己更新它使用的列表...

+1

請發佈此代碼。這將有很大的幫助。 – 2012-06-20 14:56:36

+3

從服務器添加自動完成功能的最簡單方法(服務器需要發送JSON響應)https://github.com/mobisystech/autocompletetextview – Veer 2014-04-12 15:30:24

+0

@Veer。非常感謝你。非常好的元素,我很高興。 – Bakhtiyor 2014-09-12 23:43:26