我正在尝试在我为学习目的编写的一些代码中使用 SimpleCursorTreeAdapter。正在发生的事情是,当我单击父级时,它会展开并显示子级,但是我不能再做任何事情了。我使用调试器遍历代码并犯规,我被困在 looper.loop 中一个永无止境的循环中。我已经在下面的代码段中注释掉了所有实际工作的东西,但它仍然挂起。使用下面的代码段,我希望单击第二个父级会导致它展开(如箭头变化所示)。我在代码中留下了旧的东西(但被注释掉了)来展示我想要做什么。
我真的很感激任何意见或建议。
private void showEvents(final Cursor cursor) {
ExpandableListView lv1 = this.getExpandableListView();
SimpleCursorTreeAdapter adapter = new SimpleCursorTreeAdapter (this, cursor, R.layout.simplerow, FROM, TO,
R.layout.childrow, FROMCHILD, TOCHILD) {
//@Override
//public void setViewText(TextView v, String text) {
// super.setViewText(v, convText(v, text, cursor));
//}
@Override
protected Cursor getChildrenCursor(Cursor parentCursor) {
int groupPos = parentCursor.getPosition();
Log.d("TEST", "getChildrenCursor() for groupPos " + groupPos);
String sql = "select f._id, f.NAME as ASSETCLASS, "
+ "f.value as AMOUNT, "
+ "0 as PERCENTAGE, "
+ "0 as TARGET "
+ "from funds f "
+ "where f.asset_class = " + parentCursor.getInt(0) + ";";
sql = "select f._id, f.NAME as FUNDNAME, "
+ "f.value as AMOUNT_OWNED "
+ "from funds f "
+ "where 1 = 1;";
Log.d("TEST", sql);
//SQLiteDatabase db = pfdata.getReadableDatabase();
//Cursor cursor = db.rawQuery(sql, null);
//startManagingCursor(cursor);
//return cursor;
//Log.d("TEST", Integer.toString(cursor.getCount()));
//return cursor;
return null;
}
};
// Log.d("TEST", Integer.toString(adapter.getCount()));
lv1.setAdapter(adapter);
}
我尝试了这个建议,但我没有看到行为有任何变化。这是我目前拥有的:
private void showEvents(final Cursor cursor) {
ExpandableListView lv1 = this.getExpandableListView();
MyExpandableListAdapter mAdapter = new MyExpandableListAdapter(cursor, this,
R.layout.simplerow, R.layout.childrow,
FROM, TO,
FROMCHILD, TOCHILD);
lv1.setAdapter(mAdapter);
}
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
public MyExpandableListAdapter(Cursor cursor, Context context,
int groupLayout, int childLayout, String[] groupFrom,
int[] groupTo, String[] childrenFrom, int[] childrenTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childrenFrom, childrenTo);
}
@Override
protected Cursor getChildrenCursor(Cursor parentCursor) {
String sql = "select f._id, f.NAME as ASSETCLASS, "
+ "f.value as AMOUNT, "
+ "0 as PERCENTAGE, "
+ "0 as TARGET "
+ "from funds f "
+ "where f.asset_class = " + parentCursor.getInt(0) + ";";
Log.d("TEST", sql);
return null;
}
我尝试实际运行查询并返回光标,但这并没有什么不同,所以我尝试回到基础。如果有人对正在发生的事情有任何想法,我将不胜感激。