将数据从sqlhelper类的游标获取到另一个活动

时间:2013-03-22 00:23:35

标签: android android-cursoradapter

如何从其他类获取列索引(category._id或categorylang.Title)。

代码:

public Set<Category> getTopCategories() {
    final List<Integer> loadedTopCats = new ArrayList<Integer>(0);
    this.cursor = this.db.rawQuery(
            "SELECT DISTINCT category.ParentID FROM category" +
                    " INNER JOIN categorylang ON category._id = categorylang.CategoryID" +
                    " INNER JOIN questiontable" +
                    " ON categorylang.CategoryID = questiontable.CategoryID" +
                    " WHERE category.ParentID != 0" +
                    " AND questiontable.QuestionID IS NOT NULL" ,
                    null);

    while (this.cursor.moveToNext()) {
        loadedTopCats.add(this.cursor.getInt(0));
    }
    this.cursor.close();
    final StringBuilder allTopCatIds = new StringBuilder(loadedTopCats.size() * 2);

    for (final Integer i : loadedTopCats) {
        allTopCatIds.append(i + ",");
    }
    allTopCatIds.deleteCharAt(allTopCatIds.length() - 1);

    final String query = "SELECT category._id, " +
            "categorylang.Title, categorylang.Description, category.Position" +
            " FROM category" +
            " INNER JOIN categorylang" +
            " ON category._id = categorylang.CategoryID" +
            " WHERE category.ParentID = 0  AND category._id IN (" + allTopCatIds.toString() +
            ") ORDER BY category.Position DESC";
    this.cursor = this.db.rawQuery(query, null);

    SqlHelper.topCatList = new TreeSet<Category>();
    SqlHelper.catMapping = new HashMap<Integer, Set<Category>>();
    if (this.cursor.moveToFirst()) {
        do {
            SqlHelper.topCatList.add(new Category(this.cursor.getInt(0), this.cursor
                    .getString(1), "", this.cursor
                    .getString(2), this.cursor.getInt(3)));
            SqlHelper.catMapping.put(this.cursor.getInt(0), null);
        } while (this.cursor.moveToNext());
    }

    this.cursor.close();
    return SqlHelper.topCatList;
}

我的意思是:this.cursor.getInt(0),this.cursor.getString(1)将在另一个类中使用 因此,我将在另一项活动中显示最高类别列表

0 个答案:

没有答案