【问题标题】:Populate spinner from database从数据库填充微调器
【发布时间】:2011-03-12 05:51:13
【问题描述】:

我想从数据库中获取数据并在微调器中显示。 但它无法正常工作并使我的应用程序崩溃。 所以我恳请您,如果您有好的解决方案,请发送给我。

【问题讨论】:

  • ArrayAdapter arr_adp= new ArrayAdapter(this, android.R.layout.simple_spinner_item); sp.setAdapter(arr_adp); arr_adp.setDropDownViewResource(android.R.layout.simple_spinner_item);试试 { db.open();光标 cur=db.GetStudent(); int cur_item=cur.getCount(); if(cur.moveToFirst()) { 做 { arr_adp.add(cur.getString(0)); } while(cur.moveToNext()); } db.close(); } catch (Exception e) { Toast.makeText(this, "异常句柄"+e.toString(), Toast.LENGTH_LONG).show(); }

标签: android android-spinner


【解决方案1】:

查看Sample for Spinner

对于数据库示例,请参阅Notepad Application

下载 Zip 文件并检查它..

【讨论】:

  • 感谢您将我发送到良好的链接,但在微调器中显示来自数组的数据。实际上我想使用光标适配器从数据库中显示。
  • 所以,首先将数据库中的数据存储到数组中,然后将数组设置为该微调器。
猜你喜欢
  • 2011-01-12
  • 1970-01-01
  • 2020-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多