主要活动
从Sqlite& amp;获取数据的代码在可扩展列表视图中添加它。
public void getExpandableListData() {
// Group data//
Cursor cursor = databaseHelper.getGroupData();
cursor.moveToFirst();
do {
String categoryDescription = cursor.getString(cursor .getColumnIndex("categorydesc"));
int categoryId = cursor.getInt(cursor.getColumnIndex("CategoryId"));
listDataHeader.add(categoryDescription);
// Child data//
Cursor cursorChild = databaseHelper.getChildData(categoryId);
List<ChildInfo> childList = new ArrayList<ChildInfo>();
cursorChild.moveToFirst();
while (cursorChild.moveToNext()) {
String businessName = cursorChild.getString(cursorChild.getColumnIndex("BusinessName"));
phoneNumber = cursorChild.getString(cursorChild.getColumnIndex("ph_Phone"));
String landMark = cursorChild.getString(cursorChild.getColumnIndex("LandMark"));
ChildInfo childInfo = new ChildInfo(businessName, phoneNumber, landMark);
childList.add(childInfo);
}
childDataHashMap.put(categoryDescription, childList);
} while (cursor.moveToNext());
cursor.close();
}
DataBaseHelper类
public Cursor getGroupData() {
String query = "SELECT * FROM Category GROUP BY categorydesc";
return db.rawQuery(query, null);
}
public Cursor getChildData(int CategoryId) {
String query = "SELECT * from Category WHERE CategoryId = '" + CategoryId + "' LIMIT 3" ;
return db.rawQuery(query, null);
}
在加载更多选项卡上单击我必须从Sqlite数据库获取数据并将其设置为可扩展列表视图。任何人都可以建议我如何避免重复从Sqlite获取数据并保持获取数据的数量。