0

再会!我正在使用 android 中的自动完整文本视图。这个想法是从 sqlite 中获取两列(在我的例子中是 pid、pname 和 size),并且在给定的约束下,将显示来自数据库的数据(pid、pname 和 size)。每当我测试它时,它只会显示 pname。

公共游标 getMatchingProduct(字符串约束)抛出 SQLException {

    String queryString =
            "SELECT _pid `_id`, pname, size FROM " + dbase.TABLE1;

    if (constraint != null) {
        constraint = constraint.trim() + "%";
        queryString += " WHERE pname LIKE ?";
    }
    String params[] = { constraint };

    if (constraint == null) {
        params = null;
    }
    try {
        db = dbHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery(queryString, params);
        if (cursor != null) {
            ((Activity) this.context).startManagingCursor(cursor);
            cursor.moveToFirst();
            return cursor;
        }
    }
    catch (SQLException e) {

        throw e;
    }
    db.close();
    return null;
}

任何帮助将不胜感激。

4

1 回答 1

0

I would expect the queryString to be just

String queryString = "SELECT _pid, pname, size FROM " + dbase.TABLE1;

unless your table name is actually pid and not _pid, then it would be

 String queryString = "SELECT pid, pname, size FROM " + dbase.TABLE1;
于 2013-05-14T03:20:14.333 回答