我使用JSON对象动态加载自动完成的字符串,但列表只出现在下一个字符中;如何在加载后准确显示列表?
从onTextChanged
事件调用此过程。我试图用showDropDown()
强行显示但是没有工作!!!
任何帮助?
public class HttpConnectionApiActivity extends Activity implements HttpListner, TextWatcher {
.....
AutoCompleteTextView from_txt;
List<String> country_List;
ArrayAdapter<String> adapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
from_txt = (AutoCompleteTextView) findViewById(R.id.from_txt);
//from_txt.setThreshold(1);
prepareCountryList();
from_txt.addTextChangedListener( this);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,country_List);
from_txt.setAdapter(adapter);
}
....
public void notifyHTTPRespons(final HttpHandler http) {
public void run() {
String result = http.getResponse();
try {
adapter.clear();
for (int i = 0; i < results_Array.length(); i++) {
JSONObject row = results_Array.getJSONObject(i);
String name=row.getString("name");
adapter.add(name);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
我可以通过添加以下两行来显示下拉列表: 通过在获得更新数据时重置文本非常简单。
try {
adapter.clear();
for (int i = 0; i < results_Array.length(); i++) {
JSONObject row = results_Array.getJSONObject(i);
String name=row.getString("name");
adapter.add(name);
}
//____________________
adapter.notifyDataSetChanged();
from_txt.setText(from_txt.getText());
//____________________
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}