我有一个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);
}
}