【问题标题】:Adding two .sqlite DB into a list and showing by adapter将两个 .sqlite DB 添加到列表中并由适配器显示
【发布时间】:2014-08-08 13:27:48
【问题描述】:

我在 Android 中有两个数据库 .sqlite。
productosdb.sqliteentradas.sqlite 各有一个表。
productosdb 我有表 "entradas"={id,cod1,cod2,descrip,present,pale} 和另一个 "entradas"={id,idref(that is cod1 already saved from the other table),cant,vto}

我想显示表 "entradas" 的所有项目,但给适配器一个包含两个表的所有字段的列表。当我从表"entradas" 中得到一行时,我收到消息idrefto search the other the missing fields。有些东西不工作。以下是部分代码:

private List<ProductoSUMADO> listasumada = new LinkedList<ProductoSUMADO>();  

Producto temporalProducto = new Producto();  

List<ProductoConVencimiento> temporalEntrada = new LinkedList<ProductoConVencimiento>();

String asd = bundle.getString("codigo");

temporalProducto = managerdb.getProductoPorCodigoBarras(asd);

String sss = temporalProducto.getCodprod();
temporalEntrada = db.getProductosPorIDRef(sss);

for (int pos = 0; pos < temporalEntrada.size(); pos++)
{
   ProductoSUMADO p = new ProductoSUMADO(temporalProducto.getCodbar()),
   temporalProducto.getCodprod(),
   temporalProducto.getDescrip(),
   temporalProducto.getPresent(),
   temporalProducto.getPale(),
   temporalEntrada.get(pos).getCant(),
   temporalEntrada.get(pos).getVto(),
   temporalEntrada.get(pos).getNotas());

   listasumada.add(p);
}

CustomAdapter2 adapter = new CustomAdapter2(this, listasumada);
listview.setAdapter(adapter);

也许你明白我想做什么并展示另一种方法。

【问题讨论】:

  • 我认为对于您的情况,仅发布此代码 sn-p 是不够的。有很多地方做错了。

标签: android database list sqlite listview


【解决方案1】:

你做错了。只需创建一个数据库和两个表“productos”和“entradas” 那么您将能够使用 rawQuery 加入数据。

在此处了解有关 SQLite 的更多信息:vogella

它有例子,所以你可以测试它!

加入示例:

String MY_QUERY = "SELECT * FROM table_a a INNER JOIN table_b b ON a.id=b.other_id WHERE b.property_id=?";
db.rawQuery(MY_QUERY, new String[]{String.valueOf(propertyId)});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多