【发布时间】:2014-10-17 05:40:07
【问题描述】:
我正在做一个小的安卓应用。我有 Expandable listview 并试图从 SQLite 填充数据。 所以我使用 HashMap 来存储 parent(String) 和 child(ArrayList) .
例如,我在父级(1、2、3、4)中有四个整数编号,我得到这个并存储在 ListArray 中。现在我需要为那个特定的父母获取 child(ListArray) 。父 1 包含 (aa, bb),父 2 包含 (cc).. 等等,现在看这段代码
try
{
header = new ArrayList<String>();
footer = new ArrayList<String>();
child= new HashMap<String, List<String>>();
String date = null;
int count=0, countchild=0;
Cursor c = db.rawQuery("SELECT Date FROM Table", null);
if (c.moveToFirst())
{
do
{
date=c.getString(c.getColumnIndex("Date"));
header.add(date);
count=count+1;
} while (c.moveToNext());
}
for (int i = 0; i < count; i++)
{
String temp=header.get(i);
Cursor cc=db.rawQuery("SELECT Id FROM Table WHERE Date ='"+ temp +"' ", null);
if(cc.moveToFirst())
{
do
{
countchild=countchild+1;
String id=cc.getString(cc.getColumnIndex("Id"));
//footer.clear(); // it clear all data's on child
footer.add(id);
Log.d("Footer date count", "" + countchild);
child.put(temp, footer);
}
while (cc.moveToNext());
//footer.clear(); // it clear all data's on child
}
footer.clear(); // it clear all data's on child
}
}
我想在将 footer 添加到子项后清除此处的footer,然后我才能获得正确的可扩展列表视图。如果我删除/评论此footer.clear() 行,则所有孩子都将添加到所有父母。 例如,父 1 包含(aa、bb、cc 等),父 2 包含(aa、bb、cc 等)。如果我离开这个footer.clear() 行,那么所有孩子都会被清除并只显示这样的父母,例如父母1(),父母2()......等
将footer(ListArray)添加到HashMap后如何清除它??或告诉我一些修改此代码的建议。
谢谢。斯里哈里
【问题讨论】:
标签: android sqlite arraylist hashmap expandablelistview