嗨,我正在使用带有 AsyncQueryHandler 的 ExpandableListView,如 google android 示例中给出的那样。但是我得到了一些例外,说这只应该在光标有效时调用
E/AndroidRuntime(28265): FATAL EXCEPTION: main
E/AndroidRuntime(28265): java.lang.IllegalStateException: this should only be called when the cursor is valid
E/AndroidRuntime(28265): at android.widget.CursorTreeAdapter.getGroupView(CursorTreeAdapter.java:198) E/AndroidRuntime(28265): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
E/AndroidRuntime(28265): at android.widget.AbsListView.obtainView(AbsListView.java:2290)
E/AndroidRuntime(28265): at android.widget.ListView.makeAndAddView(ListView.java:1769)
E/AndroidRuntime(28265): at android.widget.ListView.fillDown(ListView.java:672)
E/AndroidRuntime(28265): at android.widget.ListView.fillSpecific(ListView.java:1330)
E/AndroidRuntime(28265): at android.widget.ListView.layoutChildren(ListView.java:1600)
/AndroidRuntime(28265): at android.widget.AbsListView.onLayout(AbsListView.java:2141)
E/AndroidRuntime(28265): at android.view.View.layout(View.java:13844)
E/AndroidRuntime(28265): at android.view.ViewGroup.layout(ViewGroup.java:4364)
E/AndroidRuntime(28265): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1003)
E/AndroidRuntime(28265): at android.view.View.layout(View.java:13844)
我真的无法找到解决方案或破解来解决此问题
我也在尝试像这样在适配器中查询数据库
@Override
protected void bindChildView(View view, Context context, Cursor cursor,
boolean isLastChild) {
super.bindChildView(view, context, cursor, isLastChild);
TextView txtListChild = (TextView) view
.findViewById(R.id.lblListItem);
txtListChild.setTag(""+cursor.getString(cursor.getColumnIndex(CategorySub.Columns.KEY)));
}
和
@Override
protected void bindGroupView(View view, Context context, Cursor cursor,
boolean isExpanded) {
super.bindGroupView(view, context, cursor, isExpanded);
/* TextView lblListHeader = (TextView) view
.findViewById(R.id.lblListHeader);
lblListHeader.setTag(""+cursor.getString(cursor.getColumnIndex(CategoryPrimary.Columns.KEY)));
if (cursor.getPosition() % 2 != 0) {
lblListHeader
.setBackgroundResource(R.drawable.group_normal_first);
} else {
lblListHeader
.setBackgroundResource(R.drawable.group_normal_second);
}*/
}
这会产生问题吗?