如何从 SQlite 查询中获取列中的位置?

How to get position in column from SQlite query?

在 SQLITE 数据库中

public String getAllNames() {
    String selectQuery2 = "SELECT * FROM LIST ORDER BY nametype";
    SQLiteDatabase database = this.getWritableDatabase();
    Cursor cursor2 = database.rawQuery(selectQuery2, null);
    if (cursor2.moveToFirst()) {
        return cursor2.getString(15);//NAMES
    }
    database.close();
    return cursor2.getString(15);//NAMES
}

在NAME.JAVA

TextView menutype =(TextView)view.findViewById(R.id.menutype);
String m =controller.menuitems();
menutype.setText(m+"");

那么如何获取 NAMES 的位置,以便我可以根据位置 1、2 或其他位置设置字符串 m。我正在做的是使用 OnTouchListener 向左或向右滑动以获取查询中的下一个或上一个名称,然后使用 textListener 根据字符串 m 更改视图。

您可以执行 cursor.moveToPosition(int pos) 并将光标移动到需要的行,然后从移动的光标中检索名称。 如果我误解了你,而你只是想获得列 "names" 在数据库中的位置 => cursor.getColumnIndex(String columnName)