0

我有一个Cursor从我的数据库中获取一些类别,但我需要手动添加一个不在数据库中的类别,所以它们都可以在ListViewActivity. 我获得类别的方式如下:

Cursor categories = myDbHelper.getCategoriesCursor(
                    categorySelected, Tools.getLanguage());
            startManagingCursor(categories);
            CategoriesCursorAdapter categoriesAdapter = new CategoriesCursorAdapter(
                    getApplicationContext(), categories);
            setListAdapter(categoriesAdapter);

我想用我想要的字段创建一个新ArrayList<String>的并将其传递给Adapter但是我仍然无法获取这些值并将它们添加到categories列表中。

我怎么能这样做?

非常感谢提前

编辑:这是在“我的 DatabaseHelper”中获取类别的方法

public Cursor getCategoriesCursor(int parentId, int language) {
        try {
        String sql = "";
        if (parentId == 0) {
            sql = "SELECT 0 as '_id', 'Agenda' as 'name_category', 0 as 'sort' UNION ALL SELECT categories._id, name_categories.name_category, categories.sort "
                    + "FROM categories JOIN name_categories ON categories._id = name_categories.category_id "
                    + "WHERE categories.parent_id = " + parentId
                    + " AND name_categories.language_id = " + language + " ORDER BY sort";
        } else {
            sql = "SELECT categories._id, name_categories.name_category "
                    + "FROM categories JOIN name_categories ON categories._id = name_categories.category_id "
                    + "WHERE categories.parent_id = "
                    + parentId
                    + " AND name_categories.language_id = " + language + " ORDER BY sort";
        }
        Log.d("XS2TheWorld", sql);
        return myDataBase.rawQuery(sql, null);
        } catch (Exception e) {
            try {
                copyDataBase();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return getCategoriesCursor(parentId, language);
        }
    }
4

1 回答 1

0

更简单:我刚刚修改了我的 SQL 查询并且它有效

于 2012-08-22T08:34:29.543 回答