使用普通方法和volley on_response或on_error方法。我的代码是从sqlite获取数据并将其添加到数组列表并使用此列表创建适配器并将此适配器设置为autocompletetextview。我在两种方法中都使用相同的代码行,但在普通方法中,只有一个元素存在于适配器中,但在齐射方法中,适配器中将有所有元素,我无法理解问题是什么。我需要正常的方法得到工作
noramal 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 for autocompleteTextView
autocompletetextview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setLocation((String)parent.getItemAtPosition(position));
}
});
答案 0 :(得分:0)
将setAdapter
和{{1}}移到while循环之外。
如果你的两个示例都在char char的app char中,那么这已经在volley示例中完成了。