【发布时间】:2015-04-18 09:39:27
【问题描述】:
我正在将 .csv 文件中的数据插入 sqlite 数据库。但是当我从 sqlite 获取数据并将其显示到可扩展列表视图中时,它会跳过一些行数据并显示在可扩展列表视图中,即从 sqlite 显示到可扩展列表视图时缺少一些数据
主要活动
` 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);
数据库助手
public Cursor fetchGroup() {
String query = "SELECT DISTINCT CategoryId, categorydesc FROM Category ";
Cursor res = db.rawQuery(query, null);
return res;
}
public Cursor getExpandableData() {
String query = "SELECT * FROM Category GROUP BY categorydesc";
return db.rawQuery(query, null);
}
Logcat 输出
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
实际类别为 6,但仅显示其中 5 个。
【问题讨论】:
-
您能否格式化问题,以便我们在回答后阅读它。
-
修复一些格式并删除一些杂乱无章
标签: android sqlite expandablelistview expandablelistadapter