하위 체크 박스가있는 확장 가능한 목록보기가 있습니다. 이 체크 박스는 id가 "check1"인 child_helper xml에 정의되어 있습니다. 어떤 이유로 여러 개의 확인란이 서로 독립적으로 연결되어있는 것처럼 보입니다. 예를 들어 첫 번째 그룹에서 첫 번째 항목을 선택하면 해당 그룹의 모든 세 번째 항목을 선택하고 두 번째 항목을 선택하는 나머지 모든 그룹을 선택하고 두 번 건너 뛰고 다음 항목을 선택합니다.확장 가능한 목록보기 확인란을 선택하면 여러 상자가 표시됩니다.
그룹 1의 처음 세 항목을 선택하면 모든 그룹의 모든 항목이 선택됩니다. 어떻게 든 각 어린이를위한 개별 확인란 대신 3 개의 확인란 그룹을 만들었습니다. 나는 커스텀 어댑터로 문제가 해결되었다는 많은 튜토리얼을보고있다. 사용자 지정 어댑터를 사용하고 있지만 모든 기능을 사용하는 방법을 잘 모르겠습니다.
아마도 더 좋고 훨씬 짧은 질문은 어떻게 각 자식 확인란을 구별해야합니까? 이것은 내 청취자 코드입니다
덕분에
:
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.d("Enter_Foods", "onChildClick: "+childPosition);
CheckBox cb = (CheckBox)v.findViewById(R.id.check1);
if(cb != null)
cb.toggle();
return false;
}
});
}
나는 문제가 내 어댑터에서 재정의 된 방법 중 하나에 있다고 생각합니다.
ExpandableListAdapter foodCategoryExpand = new ExpandableListAdapter() {
@Override
Allitemsenabled()
other override methods...
public Object getChild(int groupPosition, int childPosition) {
switch (groupPosition) {
case 0:
return group1.get(childPosition);
case 1:
return group2.get(childPosition);
case 2:
return group3.get(childPosition);
default:
return null;
}
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder holder;
if (convertView == null) {
holder = new ChildHolder();
LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this);
convertView = inflator.inflate(R.layout.enter_foods_child_helper,null);
holder.tvChild = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_child);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
//switch based on which group (main heading) child is in
switch (groupPosition) {
case 0:
holder.tvChild.setText(group1.get(childPosition));
break;
case 1:
holder.tvChild.setText(group2.get(childPosition));
break;
case 2:
holder.tvChild.setText(group3.get(childPosition));
break;
}
return convertView;
}
//create Group (main heading) view
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupHolder holder;
if (convertView == null) {
holder = new GroupHolder();
LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this);
//inflate xml file and then get view from that file
convertView = inflator.inflate(R.layout.enter_foods_group_helper,null);
holder.tvGroup = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_group);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
//this actually gets the text we set in onCreate and sets it to the textView (holder)
holder.tvGroup.setText(groupTitle.get(groupPosition));
return convertView;
}
other override methods
미안 해요, 당신이 설정 한 태그 물건을 알아낼 수는 없지만 목록보기 재활용과 관련이 있습니다. 이러한보기를 재활용하기 때문에 반복적으로 목록 항목을 확인합니다. getView()에서 확장 한 각 뷰에 대해 저장 한 배열을 기반으로 선택/선택 취소해야합니다. – Kgrover
태그로 무엇을 의미합니까? 내가 listview와 어지럽 혀 시도합니다, 나는 당신이 getChildView에 대해 말하고 있다고 가정? – farnett