I have a Cursor which takes some categories from my DB, but I need to manually add a category which is not in the DB, so they can all be rendered in a ListViewActivity.
The way I get the categories is the following:
Cursor categories = myDbHelper.getCategoriesCursor(
categorySelected, Tools.getLanguage());
startManagingCursor(categories);
CategoriesCursorAdapter categoriesAdapter = new CategoriesCursorAdapter(
getApplicationContext(), categories);
setListAdapter(categoriesAdapter);
I thought of creating a new ArrayList<String> with the fields I want and passing it to the Adapter but still, I can’t grab those values and add them to the categories list.
How could I do this?
Thanks a lot in advance
EDIT: This is the method to get the categories in ‘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);
}
}
Easier: I just modified my SQL query and it worked