我有一个使用从数据库中包含数据的光标填充一个微调。看来,这是不可能的设置使用行的ID列的值微调所选项目。并且设置所选项目的唯一方法是通过使用数据集内的行的位置的。它是否正确?如果是这样,有确定比使用光标通过迭代数据行的位置的更有效的方法?
I have a Spinner that's populated using a cursor containing data from a database. It appears that it's impossible to set the selected item in the spinner using the value of the ID column of a row. And that the only way to set the selected item is by using the position of the row within the dataset. Is this correct? If so, is there a more efficient way of determining the row's position than by iterating through the dataset using the cursor?
低效率(在我看来)的方式概述here.
The inefficient (to my mind) way is outlined here.
谢谢了!
第一步,为您的数据集创建视图,联接等。
First step, create view for your data set, with joins etc.:
CREATE VIEW my_view AS
SELECT _id, field FROM my_table
第二步:
CREATE VIEW my_view2 AS
SELECT count(*) AS row_id, q1.*
FROM my_view AS q1
LEFT JOIN my_view AS q2
WHERE q1._id >= q2._id
GROUP BY q1._id
然后简单:
SELECT * FROM my_view2
结果:
row_id | _id | field
1 4 XbMCmUBFwb
2 6 Te JMejSaK
3 8 dDGMMiuRuh
4 10 phALAbnq c
5 11 EQQwPKksIj
6 12 PAt tbDnf
7 13 f zUSuhvM
8 14 TIMBgAGhkT
9 15 OOcnjKLLER
要通过id来获取位置:
To get position by id:
SELECT * FROM my_view2 WHERE _id=11
结果:
row_id | _id | field
5 11 EQQwPKksIj
希望这种帮助