我创建了一个自定义DBAdapter并创建了几个函数,包括search(),它基于rawquery语句返回游标
public Cursor search(String param) {
Cursor cursor = mDb.rawQuery("Select distinct DiagLookup._id, diagnosis, diagcode, favourite From DiagLookup Left Outer Join DiagSynonyms On DiagLookup._id = DiagSynonyms.dxid Where diagnosis = ? OR syn = ? OR diagcode = ? order by diagnosis asc", new String[]{"%"+param+"%","%"+param+"%","%"+param+"%"});
return cursor;
}
当我在我的Search ListActivity中调用search()时,它不起作用,但当我在搜索中插入以下语句时,它可以工作
public void doMySearch(String query_results) {
SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
//dbh = new DxDbAdapter(this);
//dbh.open();
String[] columns = new String[] {"diagnosis", "diagcode"};
int[] to = new int[] {R.id.diagnosis, R.id.code};
//Cursor cursor = dbh.search(query_results);
Cursor cursor = db.rawQuery("Select DiagLookup._id, diagnosis, diagcode, favourite From DiagLookup Left Outer Join DiagSynonyms On DiagLookup._id = DiagSynonyms.dxid Where diagnosis Like ? OR syn Like ? OR diagcode Like ? order by diagnosis asc", new String[]{"%"+query_results.trim()+"%","%"+query_results.trim()+"%","%"+query_results.trim()+"%"});
startManagingCursor(cursor);
adapter = new DxSimpleCursorAdapter(this,R.layout.list_detail,cursor,columns,to);
setListAdapter(adapter);
}
你可以看到我已经注释了我用我的search()函数填充光标的原始方法,这种方法不起作用......任何想法我做错了什么?
运行Cursor cursor = dbh.search(query_results);
代码时出现的错误是
couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@4053d398 has no id.
当我运行Cursor cursor = db.rawQuery("Select DiagLookup._id, diagnosis, diagcode, favourite From DiagLookup Left Outer Join DiagSynonyms On DiagLookup._id = DiagSynonyms.dxid Where diagnosis Like ? OR syn Like ? OR diagcode Like ? order by diagnosis asc", new String[]{"%"+query_results.trim()+"%","%"+query_results.trim()+"%","%"+query_results.trim()+"%"});
时,它会起作用并返回一个填充的列表视图。