【发布时间】:2014-08-18 04:03:37
【问题描述】:
我想在查看组项时展开它,但由于某些原因,我无法在展开后折叠组项。
谁能告诉我我做错了什么?
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
final GroupHolder holder;
final ViewGroup viewGroup = parent;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.group_list, null);
holder = new GroupHolder();
holder.checkbox = (CheckBox) convertView.findViewById(R.id.cb);
holder.imageView = (ImageView) convertView.findViewById(R.id.label_indicator);
holder.title = (TextView) convertView.findViewById(R.id.group_title);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
holder.imageView.setImageResource(groupStatus[groupPosition] == 0 ? R.drawable.group_down: R.drawable.group_up);
final Item groupItem = getGroup(groupPosition);
holder.title.setText(groupItem.name);
holder.checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!ALL_CHECKED) {
ArrayList<Item> childItem = getChild(groupItem);
for (Item children : childItem)
children.isChecked = isChecked;
}
groupItem.isChecked = isChecked;
// TODO Auto-generated method stub
if(groupItem.isChecked)
((ExpandableListView) viewGroup).expandGroup(groupPosition);
notifyDataSetChanged();
new Handler().postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
if (ALL_CHECKED)
ALL_CHECKED = false;
}
}, 10);
}
});
holder.checkbox.setChecked(groupItem.isChecked);
return convertView;
}
//下面是我只在group0上打勾时的logcat:
08-19 07:49:08.860: D/group pos: 0
08-19 07:49:08.863: D/group pos: 0
08-19 07:49:08.887: D/group pos: 4
我注意到当我只点击 group0 时它显示 groupId0 和 4
编辑:重新编写以使其更清楚,以便其他人更好地理解
【问题讨论】:
-
尝试调试....你在调试过程中发现了什么请告诉我。??
-
添加了调试 logcat。谢谢
-
要表明问题已解决,请单击已接受答案旁边的复选标记。
标签: android-listview expandablelistview android-checkbox oncheckedchanged