您好我尝试了这段代码,但是父级已全部设置且子级未获取任何值,并且父级点击甚至无法正常工作,并进一步展开列表以显示子级。
public class CategoryBaseAdapter extends BaseExpandableListAdapter {
private Context mContext;
private HashMap<Integer, List<ProfessionChildEntity>> mListDataChild;
private ArrayList<ProfessionEntity> mListDataGroup;
private HashMap<Integer, boolean[]> mChildCheckStates;
private ChildViewHolder childViewHolder;
private GroupViewHolder groupViewHolder;
private String groupText;
private String childText;
public CategoryBaseAdapter(Activity context,
ArrayList<ProfessionEntity> listDataGroup, HashMap<Integer, List<ProfessionChildEntity>> listDataChild) {
mContext = context;
mListDataGroup = listDataGroup;
mListDataChild = listDataChild;
mChildCheckStates = new HashMap<Integer, boolean[]>();
}
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public int getGroupCount() {
Log.d("--grpcount--",String.valueOf(mListDataGroup.size()));
return mListDataGroup.size();
}
@Override
public ProfessionEntity getGroup(int groupPosition) {
return mListDataGroup.get(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
Log.d("---poisit",String.valueOf(groupPosition));
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
groupText = getGroup(groupPosition).getDecription();
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_item, null);
groupViewHolder = new GroupViewHolder();
groupViewHolder.mGroupText = (CheckBox) convertView.findViewById(R.id.groupTextView);
convertView.setTag(groupViewHolder);
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.mGroupText.setText(groupText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
int i=mListDataChild.get(mListDataGroup.get(groupPosition).getUsesr_type()).size();
Log.d("--childrencount",String.valueOf(i));
return i;
}
@Override
public ProfessionChildEntity getChild(int groupPosition, int childPosition) {
return mListDataChild.get(mListDataGroup.get(groupPosition).getDecription()).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final int mGroupPosition = groupPosition;
final int mChildPosition = childPosition;
childText = getChild(mGroupPosition, mChildPosition).getDescription();
Log.d("---- child---",childText);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_item, null);
childViewHolder = new ChildViewHolder();
childViewHolder.mChildText = (TextView) convertView
.findViewById(R.id.childTextView);
childViewHolder.mCheckBox = (CheckBox) convertView
.findViewById(R.id.checkBox);
convertView.setTag(R.layout.child_item, null);
} else {
childViewHolder = (ChildViewHolder) convertView
.getTag(R.layout.child_item);
}
// childViewHolder.mChildText.setText(childText);
childViewHolder.mCheckBox.setOnCheckedChangeListener(null);
if (mChildCheckStates.containsKey(mGroupPosition)) {
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
childViewHolder.mCheckBox.setChecked(getChecked[mChildPosition]);
} else {
boolean getChecked[] = new boolean[getChildrenCount(mGroupPosition)];
// add getChecked[] to the mChildCheckStates hashmap using mGroupPosition as the key
mChildCheckStates.put(mGroupPosition, getChecked);
// set the check state of this position's checkbox based on the
// boolean value of getChecked[position]
childViewHolder.mCheckBox.setChecked(false);
}
childViewHolder.mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
getChecked[mChildPosition] = isChecked;
mChildCheckStates.put(mGroupPosition, getChecked);
} else {
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
getChecked[mChildPosition] = isChecked;
mChildCheckStates.put(mGroupPosition, getChecked);
}
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
}
});
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public boolean hasStableIds() {
return true;
}
public final class GroupViewHolder {
CheckBox mGroupText;
}
public final class ChildViewHolder {
TextView mChildText;
CheckBox mCheckBox;
}
}