0
正在使用正常方法抽射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));
}
});
哪裏平方米界定?在OnCreate中 –
廣場都在arrlist是相同的大小? –
定義在調試 –