Android Spinners,假设我从 SQL 中提取微调器选择,我是否也可以将它们的 SQL _id 添加到微调器值中?
我查询 SQL 数据库来填充我的微调器,用生成的书名的字符串数组填充微调器没有问题(这是一个库样式应用程序)。虽然将书名放入旋转器中进行选择没有问题,但将这些书名与其 SQL _id 联系起来的最佳方法是什么?我一直在寻找一种使旋转器“多维”的方法,但到目前为止我还不知道如何实现。
任何正确方向的帮助将不胜感激,谢谢!
I query my SQL database to populate my spinners, I have no problem populating the spinner with a string array of the resulting Book Titles (this is a library style app). While getting the Book Titles into the spinner for selection is no problem, what is the best way to tie these titles back to their SQL _id's? I've been looking for a way to make spinners "multi-dimensional" but so far I don't see how.
Any help in the right direction would be much appreciated, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您肯定需要 SimpleCursorAdapter。您必须在选择查询中包含 _id。这是一个例子...
...这会将 _id 绑定到微调器 id。因此,当您使用 onitemclicklistener 选择列表中的项目时,就像我在下面发布的那样。您将拥有与列表中的每个名称关联的正确_id...
You definitely want the SimpleCursorAdapter. You must include the _id in the select query. Here is an example...
... This will bind the _id to the spinner id. So when you select an item in the list using the onitemclicklistener like what I posted below. You will have the correct _id's associated with each of the names in the list...
我所做的是为我的微调器使用多维数组。它从
string[i][0]
中获取内容,并且 id 位于string[i][1]
中。让我获取我使用的代码。好的,它的作用是使用类变量
String[][] BookResults
来保存两个值:名称(在 [][0] 中)和 id(在 [][1] 中) 。BookResults[10][0]
是BookResults[10][1]
ID 的图书名称。本示例中的“搜索按钮”显示了如何获取这两个值。What I did is used a multidimensional array for my spinner. It grabs things from
string[i][0]
and the ids are instring[i][1]
. Let me grab the code I used for it.Okay, so what this does is uses a class variable
String[][] BookResults
to hold both values, the name (in [][0]) and the id (in [][1]).BookResults[10][0]
would be the book name forBookResults[10][1]
's ID. The "search button" in this example shows how you'd get both values.考虑将 SimpleCursorAdapter 与 Spinner 和子布局的自定义视图一起使用。 :)
这是一个教程。
Look into using a SimpleCursorAdapter with your Spinner and a custom view for the child layouts. :)
Here is a tutorial.