正常方法不能正常工作,但凌空方法完美的作品
问题描述:
正在使用正常方法抽射on_response或ON_ERROR方法。我的代码是从sqlite中获取数据并将其添加到数组列表中,并使用此列表创建一个适配器并将此适配器设置为自动完成文本视图。我在这两种方法中都使用相同的代码行,但在普通方法中,只有一个元素会出现在适配器中,但在抽出方法中,适配器中将存在所有元素,我不明白是什么问题。我需要正常的方法来获取工作正常方法不能正常工作,但凌空方法完美的作品
正常运转methos:
private void prepareMyLists() {
ArrayList<String> arrlist = new ArrayList<String>();
String selectQuerys = "select distinct location from tb_user where location like" +
"'"+autoservice.getText().toString()+"%'"+" or "+"'% "+autoservice.getText().toString()+"%'";
SQLiteDatabase dbs = sq.getReadableDatabase();
Cursor cursors = dbs.rawQuery(selectQuerys, null);
while (cursors.moveToNext())
arrlist.add((cursors.getString(cursors.getColumnIndex("location"))));
adapter1 = new ArrayAdapter<String>(
getBaseContext(),
R.layout.drop_list_item,
arrlist);
autocompletetextview.setAdapter(adapter1);
}
}
凌空方法:
private void prepareMyList() {
String LOCATION = "http://android.thusharaphotos.com/sear778ch11.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST,LOCATION, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
ArrayList<String> arrlist = new ArrayList<String>();
String selectQuerys = "select distinct location from tb_user where location like" +
"'"+autoservice.getText().toString()+"%'"+" or "+"'% "+autoservice.getText().toString()+"%'";
SQLiteDatabase dbs = sq.getReadableDatabase();
Cursor cursors = dbs.rawQuery(selectQuerys, null);
while (cursors.moveToNext())
arrlist.add((cursors.getString(cursors.getColumnIndex("location"))));
adapter1 = new ArrayAdapter<String>(
getBaseContext(),
R.layout.drop_list_item,
arrlist);
autocompletetextview.setAdapter(adapter1);
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("location_name", autoservice.getText().toString());
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getBaseContext());
requestQueue.add(stringRequest);
}
的onclick为autocompleteTextView
autocompletetextview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setLocation((String)parent.getItemAtPosition(position));
}
});
答
移动你的new ArrayAdapter
和setAdapter
while循环外。
如果同时你的例子是在应用程序字符在char,这已经是在凌空例子来完成。
+0
没有改变同样的问题 –
哪里平方米界定?在OnCreate中 –
广场都在arrlist是相同的大小? –
定义在调试 –