我有一个Cursor
从我的数据库中获取一些类别,但我需要手动添加一个不在数据库中的类别,因此它们都可以在ListViewActivity
中呈现。
我得到类别的方式如下:
Cursor categories = myDbHelper.getCategoriesCursor(
categorySelected, Tools.getLanguage());
startManagingCursor(categories);
CategoriesCursorAdapter categoriesAdapter = new CategoriesCursorAdapter(
getApplicationContext(), categories);
setListAdapter(categoriesAdapter);
我想创建一个包含我想要的字段的新ArrayList<String>
并将其传递给Adapter
,但我仍然无法获取这些值并将其添加到categories
列表中
我怎么能这样做?
提前多多感谢
编辑:这是获取'my 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);
}
}
答案 0 :(得分:0)
更简单:我刚刚修改了我的SQL查询并且工作正常