반응형
확장 가능한 목록보기에서 모든 하위 항목 확장
확장 가능한 목록보기가 채워지는 동안 모든 하위 항목을 확장하고 싶습니다. 현재 내 코드는 다음과 같습니다.
ExpandableListView listView = (ExpandableListView) findViewById(R.id.view);
int count = viewAdapted.getGroupCount();
for (int position = 1; position <= count; position++)
listView.expandGroup(position - 1);
꽤 추합니다. 이 작업을 수행하는 더 좋은 방법이 있습니까?
사용자 정의 어댑터의 getGroupView에서 확장 할 수 있습니다.
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView mExpandableListView = (ExpandableListView) parent;
mExpandableListView.expandGroup(groupPosition);
return v;
}
Gluck!
이 코드를 어댑터에 넣으면 확장 목록이 열린 상태로 유지되고 닫기 기능이 비활성화됩니다.
ExpandableListView mExpandableListView = (ExpandableListView) parent;
mExpandableListView.expandGroup(groupPosition);
이것은 약간의 해결 방법이 될 수 있지만 제대로 작동합니다. 모든 그룹을 열고 (시작시) 언제든지 닫을 수 있습니다.
for ( int i = 0; i < groupList.getCount(); i++ ) {
groupList.expandGroup(i);
}
참고 : 확장 가능한보기에서 어댑터를 설정 한 후이 코드를 넣으십시오. 그렇지 않으면 오류가 발생할 수 있습니다. 도움이 되었기를 바랍니다.
이 코드를 oncreate 메소드에 넣는 것보다 먼저 어댑터를 채우십시오.
int count = adapter.getGroupCount();
for ( int i = 0; i < count; i++ )
listView.expandGroup(i);
모든 그룹 확장
for(int i=0; i < myAdapter.getGroupCount(); i++)
myExpandableListView.expandGroup(i);
접을 수 없게 만들고 싶다면.
myExpandableListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) {
return true;
}
});
나열된 응답을 시도했지만 getGroupCount () 메서드를 사용하여 그룹 수를 가져올 수 있음을 발견했습니다 .
이 방법을 사용하여 모든 그룹을 반복하고 확장 할 수 있습니다. ExpandableListView
for (int i = 0; i < myExpandableListView.getExpandableListAdapter().getGroupCount(); i++) {
//Expand group
myExpandableListView.expandGroup(i);
}
참고 URL : https://stackoverflow.com/questions/6873345/expand-all-children-in-expandable-list-view
반응형
'developer tip' 카테고리의 다른 글
HTML에서 IMG의 높이 및 너비 속성을 지정해야합니까? (0) | 2020.10.27 |
---|---|
dict를 올바르게 하위 클래스로 만들고 __getitem__ 및 __setitem__을 재정의하는 방법 (0) | 2020.10.27 |
재생성 된 활동에 Retrofit 콜백을 구현하는 모범 사례? (0) | 2020.10.27 |
grep을 통해 텍스트 파일에서 빈 줄 제거 (0) | 2020.10.26 |
엔티티 프레임 워크 지정된 메타 데이터 리소스를로드 할 수 없습니다. (0) | 2020.10.26 |