【问题标题】:How to SQLite database to Custom ListView?如何 SQLite 数据库到自定义 ListView?
【发布时间】:2018-03-05 23:37:50
【问题描述】:

我一直在开发一个通过strings.xml 文件夹中的字符串数组实现自定义列表视图的android 应用程序。但是现在我想合并一个 Sql-lite 数据库来获取 Listviews 的数据,它看起来像这样,但我想要来自 sq-lite 数据库的数据:

我将如何从字符串数组切换或首先从数据库中获取数据

编辑:我已经研究过实现 sqlite 我想知道如何将数据从数据库获取到列表视图?

【问题讨论】:

  • 如何在 google 上搜索一下如何在 Android 应用中实现 SQLite 数据库?
  • 您需要一个Adapter,您可以关注this answer 以获取工作示例。对于数据库部分,您需要首先检索List 中的所有记录,然后按照示例将其传递给Adapter

标签: java android sqlite


【解决方案1】:

Tutorial to Implement SQLite in Android.

首先您需要实现 SQLite 数据库,然后在数据库中进行查询以将所有数据放入一个字符串数组中,然后使用该字符串数组填充 ListView。 你可以这样做:

List<String> nameArray = new ArrayList<String>();
List<String> chargeArray = new ArrayList<String>();
String data="";
while(crs.moveToNext()){
    data = crs.getString(crs.getColumnIndex("NAME"));
    nameArray.add(data);
    data = crs.getString(crs.getColumnIndex("CHARGE"));
    chargeArray.add(data);
}

您可以查看此link 以供参考。

【讨论】:

  • 谢谢@Pronoy 抱歉看起来很简单,但我想多了
猜你喜欢
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-31
  • 2022-01-12
  • 2011-05-30
相关资源
最近更新 更多