I am inserting data from .csv file into sqlite database.But when I am fetching data from sqlite & showing it into Expandable list view,it skips some row data and showing in Expandable list view i.e. Some data is missing while showing from sqlite to Expandable list view
Main Activity
databaseHelper = new DatabaseHelper(this);
listDataHeader = new ArrayList<String>();
childDataHashMap = new HashMap<String, List<ChildInfo>>();`
// get the listview
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
// ****************************Group data******************************//
Cursor cursor = databaseHelper.getExpandableData();
cursor.moveToFirst();
Log.i(TAG, "cursor.getCount()" + cursor.getCount());
do {
Log.d(TAG,"Category "+ cursor.getString(cursor .getColumnIndex("categorydesc")));
String categoryDescription = cursor.getString(cursor .getColumnIndex("categorydesc"));
int categoryId = cursor.getInt(cursor.getColumnIndex("CategoryId"));
Log.i(TAG, "categoryDescription:" + categoryDescription);
listDataHeader.add(categoryDescription);
// ****************************Child data******************************//
Cursor cursorChild = databaseHelper.fetchChildren(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"));
Log.w("", "Category Child " + businessName);
ChildInfo childInfo = new ChildInfo(businessName, phoneNumber,landMark);
childList.add(childInfo);
}
childDataHashMap.put(categoryDescription, childList);
} while (cursor.moveToNext());
cursor.close();
listAdapter = new ExpandableListAdapterNew(this, listDataHeader,childDataHashMap);
// setting list adapter
expListView.setAdapter(listAdapter);
Database Helper
/** Fetch group.
* @return the cursor
*/
public Cursor fetchGroup() {
//String query = "SELECT DISTINCT CategoryId, categorydesc FROM Category ";
String query = "SELECT DISTINCT CategoryId, categorydesc, FROM Category";
Cursor res = db.rawQuery(query, null);
return res;
}
/** Gets the expandable data.
* @return the expandable data
*/
public Cursor getExpandableData() {
String query = "SELECT * FROM Category GROUP BY categorydesc";
return db.rawQuery(query, null);
}
Logcat output
Number of Records(10600): :: 11
MainAcitivity(10600): cursor.getCount()6
Category Hotels
categoryDescription:Hotels
Category Child GoodLuck
Category Restaurants
categoryDescription:Restaurants
Category Child ByThe Way
Category School
categoryDescription:School
Category Child Ornellas
Category Stationary
categoryDescription:Stationary
Category Child Venus
Category super shopee
Actual categories are 6 but it's showing only 5 of them.Please suggest me solution for it
Aucun commentaire:
Enregistrer un commentaire