Android SQL:Query()其中COL=int而不是string?(内部图片和代码)

Android SQL:Query()其中COL=int而不是string?(内部图片和代码),android,sql,database,integer,Android,Sql,Database,Integer,这是我的问题的解释。 应用程序说明:我希望应用程序根据用户单击的按钮显示具有不同内容的列表视图。为此,在我的数据库中有一个带有数字(1或2)的列,我希望单击按钮1仅显示该数字为1的元素,依此类推 A.当用户单击一个按钮(称为button1)时,它会打开一个新的活动(ResultListViewActivity),并通过putExtra发送一个名为“myVariable”的整数 private OnClickListener listener_button1 = new OnClickListen

这是我的问题的解释。
应用程序说明:我希望应用程序根据用户单击的按钮显示具有不同内容的列表视图。为此,在我的数据库中有一个带有数字(1或2)的列,我希望单击按钮1仅显示该数字为1的元素,依此类推

A.当用户单击一个按钮(称为button1)时,它会打开一个新的活动(ResultListViewActivity),并通过putExtra发送一个名为“myVariable”的整数

private OnClickListener listener_button1 = new OnClickListener() {
    public void onClick(View v) {
        Intent t = new Intent(MainActivity.this,
                ResultListViewActivity.class);
        t.putExtra("myVariable", 1);
        startActivity(t);

    }

};
B.在ResultListViewActivity中,有一个方法(FindNameTable)使用此整数作为输入:

private void displayListView() {

    Bundle bundle = getIntent().getExtras();
    int myVariable = bundle.getInt("myVariable");

    Cursor c = dbHelper.findNameInTable(myVariable);
    // the desired columns to be bound
    String[] columns = new String[] { DatabaseAdapter.COL_NAME,
            DatabaseAdapter.COL_COMMENTS, };
    // the XML defined views which the data will be bound to
    int[] to = new int[] { R.id.name, R.id.comments, };
    // create the adapter using the cursor pointing to the desired data
    // as well as the layout information
    cursorAdapter = new SimpleCursorAdapter(this, R.layout.poi_info, c,
            columns, to, 0);

    ListView listView = (ListView) findViewById(R.id.listview);
    // Assign adapter to ListView
    listView.setAdapter(cursorAdapter);
}
C.此方法findNameTable()在我的DatabaseAdapter类中定义如下:

    public Cursor findNameInTable(int myVariable) {
    c = myDatabase
            .query(DATABASE_TABLE, new String[] { COL_NAME , COL_COMMENTS }, COL_CAT1 = myVariable,
                    new String[] { Integer.toString(myVariable) }, null,
                    null, null);
    return c;
} 
我希望此方法返回一个游标,其中对于COL_CAT1=myVariable的数据库的每一行,都有COL_NAME(列名)和COL_注释的内容(例如,如果我单击按钮1,则为1)

我尝试使用Integer.toString(myVariable)将int转换为字符串,但仍然无法工作。此外,在我的活动之外,我对COL_CAT1的定义如下:

    public static final String COL_CAT1 = "cat1";
我真的希望这足够清楚,有人会帮助我完成这项工作,我真的开始对这件事感到绝望

提前谢谢

编辑:发布代码而不是图片

将查询更改为:

 c=mydatabase.query(
            DATABASE_TABLE,
            new String[] { COL_NAME,COL_COMMENTS },
            COL_CAT1 + "=?" ,
            new String[] { Integer.toString(myVariable) }, null, null, null
        );
将您的查询更改为:

 c=mydatabase.query(
            DATABASE_TABLE,
            new String[] { COL_NAME,COL_COMMENTS },
            COL_CAT1 + "=?" ,
            new String[] { Integer.toString(myVariable) }, null, null, null
        );

您确实意识到没有人想重新键入您的代码,并且通过使用屏幕截图而不是文本,您几乎强迫他们这样做,是吗?很抱歉,编辑了我的帖子。@Phalanx使用COL_CAT1+“=?”而不是COL_CAT1=myVariable@JaiSoni:工作正常,不再显示错误消息。我的应用程序仍然无法运行,但它可能来自其他方面,非常感谢!您确实意识到没有人想重新键入您的代码,并且通过使用屏幕截图而不是文本,您几乎强迫他们这样做,是吗?很抱歉,编辑了我的帖子。@Phalanx使用COL_CAT1+“=?”而不是COL_CAT1=myVariable@JaiSoni:工作正常,不再显示错误消息。我的应用程序仍然无法运行,但它可能来自其他方面,非常感谢!