Android Spinners, say I pull spinner selections from SQL, can I also add their SQL _id#39;s to the spinner values?(Android微调工具,比如我从SQL中选择了微调工具,我是否也可以将它们的SQL_id;添加到微调器值中?)
本文介绍了Android微调工具,比如我从SQL中选择了微调工具,我是否也可以将它们的SQL_id;添加到微调器值中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我查询我的SQL数据库来填充我的微调工具,我可以毫不费力地使用结果图书标题的字符串数组来填充微调工具(这是一个图书馆风格的应用程序)。虽然将图书标题放入微调工具以供选择是没有问题的,但是将这些图书与其SQL_id绑定的最佳方式是什么?我一直在寻找一种方法来使微调工具变得"多维",但到目前为止我还没有找到方法。
任何方向正确的帮助都将不胜感激,谢谢!
推荐答案
您肯定需要SimpleCursorAdapter。您必须在SELECT查询中包括_id。这里有一个例子...
Spinner spinner = (Spinner) dialog.findViewById(R.id.mm_spinner);
// DatabaseInterface would be your data access class...
DatabaseInterface db = new DatabaseInterface(this);
db.open();
Cursor c = db.getNames(); // This would contain _id, name from a database for example.
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item,
c,
new String[] {DatabaseInterface.KEY_ID, DatabaseInterface.KEY_NAME},
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
.这会将_id绑定到微调ID。因此,当您像我在下面发布的那样,使用nitemclicklistener在列表中选择一个项目时。您将使正确的_id与列表中的每个名称相关联...
spinner.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id){
// id = the _id from the cursor
}
});
这篇关于Android微调工具,比如我从SQL中选择了微调工具,我是否也可以将它们的SQL_id;添加到微调器值中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Android微调工具,比如我从SQL中选择了微调工具,我是否也可以将它们的SQL_id;添加到微调器值中?


猜你喜欢
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01