【发布时间】:2015-05-21 15:55:39
【问题描述】:
我有一个类可以根据从服务器输入的文本获取所有建议。在 postExecute() 中,我将所有建议添加到我的 ArrayList 中,并且我想将该 arraylist 设置为适配器。但它不起作用。
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();
}
}
所以建议出现在数组列表中,但它没有立即显示为下拉列表.. 请帮忙, 提前谢谢。
【问题讨论】:
标签: android android-activity autocompletetextview