-1

当以这种方式单击微调器时,我试图检索_id我的表格的真实内容:

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String c = parent.getSelectedItem().toString();
    long id_mark = parent.getItemIdAtPosition(position);
    Toast.makeText(parent.getContext(), "Category: " + c + " | _id: " + id_mark, Toast.LENGTH_LONG).show();
}

我的表:(用户删除了一些列)

_id | category_name
---------------------
1   | NAME_HERE_1
3   | NAME_HERE_2
4   | NAME_HERE_3
7   | NAME_HERE_4

Toast 输出为:

Category: NAME_HERE_2 | _id: 2

但与我的桌子id_mark不同_id。那么如何进行呢?提前致谢!

4

1 回答 1

0

But the id_mark is different of _id of the my table. So how to proceed?

If you're using a CursorAdapter and want _id from your table, simply use the forth parameter id in onItemSelected(). id already holds the table's primary key for the selected row.

于 2013-02-20T17:07:49.990 回答