【发布时间】:2014-10-21 22:37:05
【问题描述】:
我正在学习如何创建一个从 SQLite 加载下拉列表的微调器。我有一个由微调器和表格组成的 UI。如果用户单击微调器,则表的内容将根据基于微调器上所选 ID 的数据库加载。如果未选择名称,它将加载表格中的所有内容。但是我找不到如何根据微调器上选择的 ID / 名称重新加载表格的方法。谁能指导我?
表本身是一个连接表,其结构如下:
表 A:ID_Person |姓名 |年龄
表 B:ID_Account | ID_Person |金额
Spinner 显示人的名字。同时表格将显示以下结构:
姓名 |年龄 |金额
我的微调器代码:
public List<String> getAllDealers()
{
List<String> contentdealer = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM " +Dealer_TABLE;
cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
contentdealer.add(cursor.getString(1));
} while (cursor.moveToNext());
}
// closing connection
return contentdealer;
}
这是我构建循环的表格的方法:
Cursor c = in.getViewInfo(); //method in db consists of query that i want table show
int rows = c.getCount();
int cols = c.getColumnCount();
c.moveToFirst();
// outer for loop
for (int i = 0; i < rows; i++)
{
//looping all rows based .getCount()
//looping all columns
for (int j = 0; j < cols; j++)
{
}
}
in.close();
【问题讨论】:
标签: android database sqlite android-spinner android-tablelayout