グループIDが私が持っている配列リストにある場合、グループを展開して折りたたもうとしています。
これは私がそれを行う方法です:
final Group group = (Group) getGroup(groupPosition);
ExpandableListView eLV = (ExpandableListView) parent;
if ( subscriptions != null ) {
if ( subscriptions.contains(group.getID()) ) {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(true);
eLV.expandGroup(groupPosition);
} else {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(false);
eLV.collapseGroup(groupPosition);
}
}
グループが初めてロードされ、正しいグループが展開されたときに機能します。また、グループを押すと、予想どおり崩壊します。
しかし、グループを展開したり、グループを選択したりすると、アプリがクラッシュします。eLV.collapseGroup(groupPosition);の部分を削除した場合にのみ IT が発生します。それが再び機能するelseブロックから。しかし、その後、明らかな理由で崩壊することはできません..
これは例外です:
03-27 09:29:11.059: W/dalvikvm(21674): threadid=1: thread exiting with uncaught exception (group=0x40bec1f8)
03-27 09:29:11.067: E/AndroidRuntime(21674): FATAL EXCEPTION: main
03-27 09:29:11.067: E/AndroidRuntime(21674): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
03-27 09:29:11.067: E/AndroidRuntime(21674): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
03-27 09:29:11.067: E/AndroidRuntime(21674): at java.util.ArrayList.get(ArrayList.java:304)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:225)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.AbsListView.obtainView(AbsListView.java:2210)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.ListView.onMeasure(ListView.java:1155)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1027)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.onMeasure(LinearLayout.java:565)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.measureVertical(LinearLayout.java:670)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4709)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-27 09:29:11.067: E/AndroidRuntime(21674): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2240)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.View.measure(View.java:12775)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1092)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.os.Looper.loop(Looper.java:137)
03-27 09:29:11.067: E/AndroidRuntime(21674): at android.app.ActivityThread.main(ActivityThread.java:4514)
03-27 09:29:11.067: E/AndroidRuntime(21674): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 09:29:11.067: E/AndroidRuntime(21674): at java.lang.reflect.Method.invoke(Method.java:511)
03-27 09:29:11.067: E/AndroidRuntime(21674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
03-27 09:29:11.067: E/AndroidRuntime(21674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-27 09:29:11.067: E/AndroidRuntime(21674): at dalvik.system.NativeStart.main(Native Method)
完全な機能:
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,ViewGroup parent) {
View v;
if (convertView == null) {
v = newGroupView(isExpanded, parent);
} else {
v = convertView;
}
final Group group = (Group) getGroup(groupPosition);
ExpandableListView eLV = (ExpandableListView) parent;
if ( subscriptions != null ) {
if ( subscriptions.contains(group.getID()) ) {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(true);
eLV.expandGroup(groupPosition);
} else {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(false);
eLV.collapseGroup(groupPosition);
}
}
if ( isExpanded ) {
if ( subscriptions.contains(group.getID()) == false ) {
subscriptions.add(group.getID());
}
} else {
for (int i=0;i<subscriptions.size();i++) {
if ( subscriptions.get(i).equals(group.getID())) {
subscriptions.remove(i);
}
}
}
bindGroupView(groupPosition, isExpanded, v, parent);
return v;
}