从填充独立的SQL表一个ListView [英] populating a ListView from separate sql tables

查看:151
本文介绍了从填充独立的SQL表一个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所试图做的是填充一个列表视图,从我的数据库中的两个不同的表。我使用的表是:

What I am trying to do is populate one listview, from two different tables in my database. The tables that I am using are:

--------------------------
|UNIT_TABLE|SHOVEL_TABLE |
|ID        |ID           |
|SITE_NAME |SITE_NAME    |
|UNIT_NAME |SHOVEL_NAME  |
--------------------------

的ID在我所有的表上,作为一个基本的自动增量不为空,则SITE_NAME是那里的UNIT_TABLE和SHOVEL_TABLE正在以完成的名称。

The id is used in all my tables, as a basic autoincrement not null, the SITE_NAME is the name of the where the UNIT_TABLE and SHOVEL_TABLE are being completed at.

在上最佳的选择一些研究,我决定使用以下code创建使用SITE_NAME确定我需要哪些在两个表的联接。

After some research on the best option I decided to use the following code to create a join on the two tables using the SITE_NAME to determine which ones I need.

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String[] queries=new String[]{"select "+ID+", "+SHOVEL_NAME+" from "+SHOVEL_TABLE+" where "+SITE_NAME+"='"+Site+"'",
            "select "+ID+", "+ UNIT_NAME+" from "+UNIT_TABLE+" where "+SITE_NAME+"='"+Site+"'"};
    String SQL= qb.buildUnionQuery(queries, null, null);

这让我所有的数据合并到一个表,并使用SimpleCursorAdapter填充我的列表视图。然而,当我点击一个列表项,它带我到相同的活动。我需要做的是,如果该项目来自于SHOVEL_TABLE走一Shovel.class,如果从UNIT_TABLE来到我需要它去Unit.class。

This allowed me to combine all the data into one table, and populate my listview using a SimpleCursorAdapter. However, when I click on a list item, it takes me to the same activity. What I need it to do is if the item came from the SHOVEL_TABLE to go one Shovel.class, and if it came from the UNIT_TABLE I need it to go Unit.class.

寻找任何建议。

推荐答案

我假设你在你的填充的ListView权?巢穴我在适配器猜测使用的适配器,就可以把额外的信息为您listitemlistener注意的。

i assume that you use an adapter in populating your listview right?, den i guess in your adapter, you can put added info for your listitemlistener to take note on.

这篇关于从填充独立的SQL表一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆