Android:从 SimpleCursorAdapter 获取位置
我想设置微调器项目的位置,但微调器正在使用带有数据库数据的简单游标适配器填充。我想从数据库中获取当前字符串,然后将微调器设置为该值。我知道通过使用 arrayadapter 我可以通过这种方式从适配器获取位置:
String myString = queryData.getString(queryData.getColumnIndex("myString"));
//cast to an ArrayAdapter
mySpinnerAdapter adapter = (mySpinnerAdapter) mySpinner.getAdapter();
int spinnerPosition = ?
//set the default according to value
mySpinner.setSelection(spinnerPosition);
但是有没有办法从 SimpleCursorAdapter 获取项目的位置?过去,我总是沿着光标适配器构建一个旋转器数据数组,但这似乎是一种肮脏的做法。如果这是唯一的方法的话...
I would like to set the position of a spinner item, but the spinner is being populated with a simplecursoradapter with data from a database. I would like to get the current string from the database, then set the spinner to that value. I know that by using an arrayadapter I can get the position from the adapter this way:
String myString = queryData.getString(queryData.getColumnIndex("myString"));
//cast to an ArrayAdapter
mySpinnerAdapter adapter = (mySpinnerAdapter) mySpinner.getAdapter();
int spinnerPosition = ?
//set the default according to value
mySpinner.setSelection(spinnerPosition);
But is there a way to get the position of an item from a SimpleCursorAdapter? In the past I have always build an array of my spinner data along side the cursoradapter, but this seems like a dirty way of doing it. If its the only way though...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过执行以下操作来获取项目的位置:
You can get the position of the item by doing this:
即使我也面临同样的问题。在我花了几个小时的时间后,我找到了这个解决方案。
我希望它能帮助你。
Even i face the same problem. After breaking my head for some hours, i found this solution.
I hope it will help you.