0
我有一個類可以根據從服務器輸入的文本提取所有建議。在postExecute()中,我將所有建議添加到我的ArrayList中,並且我想將該ArrayList設置爲適配器。但它不起作用。未設置AutoCompleteTextView適配器
的的onCreate()代碼:
t1 = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
t1.setThreshold(1);
t1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
//DoPost() is the class fetching data from server
new DoPOST().execute("");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,Names);
t1.setAdapter(adp);
當我改變文本,我可以看到服務器響應返回數據。而在postExecute():
for(int i=0 ;i<js.length();i++){
try {
JSONObject tokenobj=js.getJSONObject(i);
Names.add(tokenobj.get("suggestion").toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
所以建議在ArrayList中來,但它沒有顯示爲下拉瞬間.. 請幫幫忙, Thanx提前。
請參閱http://stackoverflow.com/q/30366972/2252830 – pskink