1
의 제안을 채우는하지 : 나는 디버깅 할 때, 나는 suggestion_name 배열 것을 볼CursorAdapter 내가 문자열 요소의 배열을 SearchView
for (int i=0; i<suggestion_name.length;i++){
suggestion_name[i] = main_data.getJSONArray("cafe").getJSONObject(i).getString("name");
}
: 일부 JSON 데이터로 채워집니다
suggestion_name = new String[main_data.getJSONArray("cafe").length()];
그것의 2 개의 요소 (여기의 모든 것은 멋지다).
public void set_suggestion_adapter_array(){
String[] from = new String[] {"cafe_name"};
int[] to = new int[] {R.id.suggestionTextView};
cursorAdapter = new SimpleCursorAdapter(a,
R.layout.suggestions_single_item,
null,
from,
to,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}
을이 같은 제안 목록을 채울 : 그럼 다음과 같이 내 제안 어댑터를 만들
public void populate(String text){
MatrixCursor matrixCursor = new MatrixCursor(new String[]{ BaseColumns._ID, "cafe_name" });
for (int i=0; i<suggestion_name.length; i++) {
if (suggestion_name[i].toLowerCase().startsWith(text.toLowerCase()))
matrixCursor.addRow(new Object[] {i, suggestion_name[i]});
}
cursorAdapter.changeCursor(matrixCursor);
cursorAdapter.notifyDataSetChanged();
}
내가 onQueryTextChange에서 채우기() 메소드 호출 해요 :
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// search database for query
getDataMap.search(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
// show suggestions
getDataMap.populate(newText);
return true;
}
});
을 그러나 제안 필드의 요소를 검색 필드에 입력하기 시작하면 제안이 없습니다. 여러 번 디버깅하여 내 코드가 시간에 호출되지 않는지 확인하지만 모든 것이 완벽하게 작동합니다. 내 배열 요소에는 이상한 문자, 기호 등이 없습니다. 여기에 무엇을 놓치고 있습니까? 감사.