对自动完成执行过滤
我有一个自动完成功能,当我开始输入时,我会显示数据库中两列的内容。
现在,我想对此执行过滤,并实现了以下方法:
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }
String filter="";
if(constraint==null) filter="";
else filter=constraint.toString();
Cursor cursor=db.getCursor(filter);
return cursor;
}
我的类中操作数据库的方法如下所示:
public Cursor getCursor(String prefix) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String[] args = {prefix};
queryBuilder.setTables(TABLE_2);
String[] asColumnsToReturn = new String[] {"route","user_id"};
Cursor mCursor = queryBuilder.query(db,asColumnsToReturn,null, args, null, null,null);
int idcol = mCursor.getColumnIndexOrThrow(KEY_ROUTE);
int kwcol = mCursor.getColumnIndexOrThrow(KEY_USER_ID );
while(mCursor.moveToNext()) {
String id = mCursor.getString(idcol);
String kw = mCursor.getString(kwcol);
Log.d(id,kw);
}
return mCursor;
}
问题:为什么我的自动完成中没有显示任何内容???
这就是我的 logcat 的样子:
05-01 09:28:59.207: WARN/Filter(366): An exception occured during performFiltering()!
05-01 09:28:59.207: WARN/Filter(366): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x3114b8
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:190)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:55)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1220)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:316)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:266)
05-01 09:28:59.207: WARN/Filter(366): at com.server.DBAdapter.getCursor(DBAdapter.java:199)
05-01 09:28:59.207: WARN/Filter(366): at com.server.Server8$ContactListCursorAdapter.runQueryOnBackgroundThread(Server8.java:185)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.CursorFilter.performFiltering(CursorFilter.java:49)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-01 09:28:59.207: WARN/Filter(366): at android.os.Looper.loop(Looper.java:123)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.HandlerThread.run(HandlerThread.java:60)
I have an autocomplete in which as I start typing I get displayed the content of two columns in a database.
Now,I wanna perfom a filtering on this and I implemented the following metod:
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }
String filter="";
if(constraint==null) filter="";
else filter=constraint.toString();
Cursor cursor=db.getCursor(filter);
return cursor;
}
The method in my class that manipulates the database looks like this:
public Cursor getCursor(String prefix) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String[] args = {prefix};
queryBuilder.setTables(TABLE_2);
String[] asColumnsToReturn = new String[] {"route","user_id"};
Cursor mCursor = queryBuilder.query(db,asColumnsToReturn,null, args, null, null,null);
int idcol = mCursor.getColumnIndexOrThrow(KEY_ROUTE);
int kwcol = mCursor.getColumnIndexOrThrow(KEY_USER_ID );
while(mCursor.moveToNext()) {
String id = mCursor.getString(idcol);
String kw = mCursor.getString(kwcol);
Log.d(id,kw);
}
return mCursor;
}
Question:Why don't I get nothing displayed in my autocomplete???
This is how my logcat looks like:
05-01 09:28:59.207: WARN/Filter(366): An exception occured during performFiltering()!
05-01 09:28:59.207: WARN/Filter(366): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x3114b8
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:190)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:55)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1220)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:316)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:266)
05-01 09:28:59.207: WARN/Filter(366): at com.server.DBAdapter.getCursor(DBAdapter.java:199)
05-01 09:28:59.207: WARN/Filter(366): at com.server.Server8$ContactListCursorAdapter.runQueryOnBackgroundThread(Server8.java:185)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.CursorFilter.performFiltering(CursorFilter.java:49)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-01 09:28:59.207: WARN/Filter(366): at android.os.Looper.loop(Looper.java:123)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.HandlerThread.run(HandlerThread.java:60)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在 while 循环之前调用 moveToFirst()
try and call moveToFirst() before the while loop