In einer Activity
, wie bekomme ich Zugriff auf die erste Gruppenansicht von Expandable ListView
? HierGet handle von Ansicht der ersten Gruppe von Expandable ListView
ist, was ich tue:
public int getFirstVisibleGroup() {
LogUtil.i(TAG, "getFirstVisibleGroup called");
int firstVis = listView.getFirstVisiblePosition();
LogUtil.i(TAG, "firstVis = " + firstVis);
long packedPosition = listView.getExpandableListPosition(firstVis);
LogUtil.i(TAG, "packedPosition = " + packedPosition);
LogUtil.i(TAG, "firstVisibleGroup = " + ExpandableListView.getPackedPositionGroup(packedPosition));
return ExpandableListView.getPackedPositionGroup(packedPosition);
}
public View getGroupView(ExpandableListView listView, int groupPosition) {
LogUtil.i(TAG, "getGroupView called");
int flatPosition = listView.getFlatListPosition(groupPosition);
LogUtil.i(TAG, "flatPosition = " + flatPosition);
int first = getFirstVisibleGroup();
LogUtil.i(TAG, "first = " + first);
LogUtil.i(TAG, "returning child at position " + (flatPosition - first));
return listView.getChildAt(flatPosition - first);
}
Und ich nenne es mit:
View view = getGroupView(listView, 0);
Letztlich wird es listView.getChildAt(0)
. Und die zurückgegebene view
ist null.
Was ist der richtige Weg?
Wann versuchen Sie 'listView.getChildAt (0)' aufzurufen? Ist das zwischen onCreate/onResume oder nachdem der Benutzer auf die Ansicht geklickt hat? – Budius
@Budius in 'onCreate()', mache ich einen Service-Anruf und wenn das Ergebnis des Service-Aufrufs gekommen ist, aktualisiere ich die 'Expandable ListView' und danach rufe ich die obige Methode auf. –