【发布时间】:2012-02-24 21:10:04
【问题描述】:
我在尝试将我的数据库加载到 Android ExpandableList 时遇到问题,我尝试使用 CursorTree 和 SimpleCursorTree 方法,但收效甚微,所以现在我正在尝试让它与 BaseExpandableListAdapter 一起使用。由于某种原因,我得到的只是类别,而不是类别的实际列表,我做错了什么?
public static String[][] sortSpellNames(){
int groupnmbr = 0;
int childnmbr = 0;
String[] aGroups = {"Combat", "Detection", "Health", "Illusion", "Manipulation"};
String[] Combat = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Combat'").getCount()],
Detection = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Detection'").getCount()],
Health = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Health'").getCount()],
Illusion = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Illusion'").getCount()],
Manipulation = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Manipulation'").getCount()];
Cursor cursor;
while(groupnmbr < aGroups.length){
childnmbr = 0;
cursor = grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like '" + aGroups[groupnmbr] + "'");
cursor.moveToFirst();
while(cursor.moveToNext()){
switch(groupnmbr){
case 0: Combat[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 1: Detection[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 2: Health[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 3: Illusion[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 4: Manipulation[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
}
childnmbr++;
}
groupnmbr++;
}
String[][] aChildren = {Combat, Detection, Health, Illusion, Manipulation};
return aChildren;
}
【问题讨论】:
-
这个看起来很奇怪:
"'Category' like '"。您正在将字符串“类别”(不是字段!)与另一个字符串进行比较。你确定这是你想要的吗? -
Category 是我数据库中列的名称,这种搜索方法适用于程序的每个部分。
标签: android database cursor expandablelistadapter