expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (prev != -1 && prev != groupPosition) {
expandableListView.collapseGroup(prev);
ImageView prevTriangle = (ImageView) expandableListView.getChildAt(prev).findViewById(R.id.triangleTop);
prevTriangle.setVisibility(View.INVISIBLE);
}
ImageView triangle = (ImageView) expandableListView.getChildAt(groupPosition).findViewById(R.id.triangleTop);
//NullPointerException Thrown here when clicking on one lower:
triangle.setVisibility(View.VISIBLE);
prev = groupPosition;
}
});
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
ImageView triangle = (ImageView) expandableListView.getChildAt(groupPosition).findViewById(R.id.triangleTop);
triangle.setVisibility(View.INVISIBLE);
}
});
这是我的代码。我试图在父视图中定位ImageView并在可见/不可见之间切换。除了扩展比在其上方扩展的父级低一个位置的父级之外,它的效果很好。此时,ImageView引用为null,但仅限于此情况。
**当我说父母较低时,我的意思是它的小组位置高一个,或者上一个+ 1。