Main Activity
Code for fetching data from Sqlite & adding it inside Expandable list view.
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 class
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);
}
On load more tab click I have to fetch data from Sqlite db and set it to Expandable list view.Can anyone please suggest me how to avoid repetition of data fetching from Sqlite and maintain count of data fetched.
Aucun commentaire:
Enregistrer un commentaire