我正在尝试访问GroupView的textview,它显示ChildView中所选复选框的计数.
例如 – North是GroupView,下面带有复选框的列表是ChildView.我想每次点击复选框更新计数(18).我在复选框上应用了OnClickListner.我有自定义ExpanadableListViewAdapter扩展BaseExpandableListAdapter.
这是我的代码片段 –
@Override
public View getGroupView(int groupPosition,boolean isExpanded,View convertView,ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.filter_expandable_list_group,parent,false);
groupViewHolder = new GroupViewHolder();
groupViewHolder.GroupName = (TextView) convertView.findViewById(R.id.group_name);
groupViewHolder.GroupCount = (TextView) convertView.findViewById(R.id.group_count);
groupViewHolder.rightArrow = (ImageView) convertView.findViewById(R.id.right_arrow);
convertView.setTag(groupViewHolder);
}else{
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.GroupName.setText(((OutletListData) getGroup(groupPosition)).getName());
groupViewHolder.GroupCount.setText(""+((OutletListData) getGroup(groupPosition)).getOutletDatas().size());
return convertView;
}
@Override
public View getChildView(final int groupPosition,final int childPosition,boolean isLastChild,final ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.filter_expandable_list_child,false);
childViewHolder = new ChildViewHolder();
childViewHolder.childTextView = (TextView) convertView.findViewById(R.id.text1);
childViewHolder.childCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(childViewHolder);
}else{
childViewHolder = (ChildViewHolder) convertView.getTag();
}
childViewHolder.childTextView.setText(((OutletData) getChild(groupPosition,childPosition)).getDealerName());
childViewHolder.childCheckBox.setChecked(((OutletData) getChild(groupPosition,childPosition)).getSelected() == "1");
childViewHolder.childCheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isChecked = ((CheckBox) v).isChecked();
ApplicationController.getEventBus().post(((OutletData) getChild(groupPosition,childPosition)).getOutletID());
if (isChecked) {
((OutletData) getChild(groupPosition,childPosition)).setSelected("1");
} else {
((OutletData) getChild(groupPosition,childPosition)).setSelected("0");
}
}
});
return convertView;
}