Checkbox 可展开列表视图-选中组和子组中的复选框
我正在开发一个可扩展的列表视图,其中包含组和子组中的复选框。我的目标是在选中组中的复选框时,也选中子组中的复选框。但现在我遇到了一个问题:如果选中了组中的复选框,那么如果我在看到所有子项后滚动列表,子项将被选中 有人能帮我解决这个问题吗?提前谢谢 这是我的适配器:Checkbox 可展开列表视图-选中组和子组中的复选框,checkbox,scroll,expandablelistview,custom-adapter,Checkbox,Scroll,Expandablelistview,Custom Adapter,我正在开发一个可扩展的列表视图,其中包含组和子组中的复选框。我的目标是在选中组中的复选框时,也选中子组中的复选框。但现在我遇到了一个问题:如果选中了组中的复选框,那么如果我在看到所有子项后滚动列表,子项将被选中 有人能帮我解决这个问题吗?提前谢谢 这是我的适配器: public class AdapterHistoryExpandable extends BaseExpandableListAdapter { private Context context; private b
public class AdapterHistoryExpandable extends BaseExpandableListAdapter {
private Context context;
private boolean checkAll = false;
private ArrayList<GroupItemsInfo> teamName;
public int isGroupChecked = 0;
HistoryHeaderActivity main;
TotalListener mListener;
class ViewHolder {
public CheckBox checkChild, checkGroup;
public TextView date, h_ps_id, h_ps_name, h_dokname, h_item, h_qty, h_service, heading;
}
public AdapterHistoryExpandable(HistoryHeaderActivity main, ArrayList<GroupItemsInfo> deptList) {
this.main = main;
this.teamName = deptList;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
}
@Override
public int getGroupCount() {
return teamName.size();
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<ChildItemsInfo> productList = teamName.get(groupPosition).getSongName();
return productList.size();
}
@Override
public Object getGroup(int groupPosition) {
return teamName.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<ChildItemsInfo> productList = teamName.get(groupPosition).getSongName();
return productList.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
public void setmListener(TotalListener mListener) {
this.mListener = mListener;
}
public void setmGroupList(ArrayList<GroupItemsInfo> mGroupList) {
this.teamName = mGroupList;
}
@Override
public View getGroupView(final int groupPosition, final boolean isExpanded, View convertView, ViewGroup parent) {
final ViewHolder holder;
final GroupItemsInfo headerInfo = (GroupItemsInfo) getGroup(groupPosition);
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) main.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_items, null);
holder.checkGroup = (CheckBox) convertView.findViewById(R.id.checkList);
holder.checkGroup.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isExpanded)
mListener.expandGroupEvent(groupPosition, isExpanded);
int getPosition = (Integer) buttonView.getTag();
headerInfo.setSelected(isChecked);
if (!isChecked) {
headerInfo.setSelected(false);
}
Intent intent = new Intent(context, AdapterHistoryExpandable.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);
}
});
convertView.setTag(holder);
convertView.setTag(R.id.checkList, holder.checkGroup);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.heading = (TextView) convertView.findViewById(R.id.heading);
holder.checkGroup.setTag(groupPosition);
holder.checkGroup.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
main.groupInfos.get(groupPosition).setSelected(buttonView.isChecked());
}
});
holder.checkGroup.setChecked(main.groupInfos.get(groupPosition).isSelected());
holder.heading.setText(headerInfo.getName().trim());
return convertView;
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ChildItemsInfo detailInfo = (ChildItemsInfo) getChild(groupPosition, childPosition);
final ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) main.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_history, null);
holder = new ViewHolder();
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.date = (TextView) convertView.findViewById(R.id.date_);
holder.h_ps_id = (TextView) convertView.findViewById(R.id.patient_id);
holder.h_ps_name = (TextView) convertView.findViewById(R.id.patient_);
holder.h_dokname = (TextView) convertView.findViewById(R.id.doctor_);
holder.h_item = (TextView) convertView.findViewById(R.id.item_);
holder.h_qty = (TextView) convertView.findViewById(R.id.qty_);
holder.h_service = (TextView) convertView.findViewById(R.id.servicetype_);
holder.checkChild = (CheckBox) convertView.findViewById(R.id.checkBox);
ModelChecking add = new ModelChecking();
if (main.groupInfos.get(groupPosition).isSelected()) {
holder.checkChild.setChecked(true);
if (holder.checkChild.isChecked()) {
add.setIDItem(detailInfo.getHitem());
add.setQtyItem(detailInfo.getHqty());
main.checkingItem.add(add);
}
} else {
holder.checkChild.setChecked(false);
main.checkingItem.clear();
}
holder.h_ps_id.setText(detailInfo.getHp_id().trim());
holder.date.setText(detailInfo.getDate().trim());
holder.h_ps_name.setText(detailInfo.getHp_name().trim());
holder.h_dokname.setText(detailInfo.getHd_name().trim());
holder.h_item.setText(detailInfo.getHitem().trim());
holder.h_qty.setText(detailInfo.getHqty().trim());
holder.h_service.setText(detailInfo.getHservice().trim());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public void onGroupExpanded(int groupPosition) {
}
@Override
public void onGroupCollapsed(int groupPosition) {
}
@Override
public long getCombinedChildId(long groupId, long childId) {
return 0;
}
@Override
public long getCombinedGroupId(long groupId) {
return 0;
}
}
公共类适配器HistoryExpandable扩展了BaseExpandableListAdapter{
私人语境;
私有布尔checkAll=false;
私有ArrayList团队名称;
public int isGroupChecked=0;
主要历史脑区活动;
总监听器;
类视图持有者{
公共复选框checkChild,checkGroup;
公共文本查看日期、h_ps_id、h_ps_名称、h_dokname、h_项目、h_数量、h_服务、标题;
}
公共适配器历史可扩展(HistoryHeaderActivity main、ArrayList deptList){
this.main=main;
this.teamName=部门列表;
}
@凌驾
公共无效注册表DataSetObserver(DataSetObserver observer){
}
@凌驾
public void unregisteredDataSetobserver(DataSetObserver观察员){
}
@凌驾
public int getGroupCount(){
返回teamName.size();
}
@凌驾
公共整数getChildrenCount(整数组位置){
ArrayList productList=teamName.get(groupPosition.getSongName();
返回productList.size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回teamName.get(groupPosition);
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
ArrayList productList=teamName.get(groupPosition.getSongName();
返回productList.get(childPosition);
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
公共布尔表ID(){
返回true;
}
公共无效设置mListener(总计设置mListener){
this.mListener=mListener;
}
公共无效setmGroupList(ArrayList mGroupList){
this.teamName=mGroupList;
}
@凌驾
公共视图getGroupView(最终int groupPosition、最终布尔值isExpanded、视图convertView、视图组父级){
最终持票人;
最终GroupItemsInfo headerInfo=(GroupItemsInfo)getGroup(groupPosition);
if(convertView==null){
holder=新的ViewHolder();
LayoutInflater充气器=(LayoutInflater)main.getSystemService(Context.LAYOUT\u充气器\u服务);
convertView=充气机。充气(R.layout.group_项目,空);
holder.checkGroup=(复选框)convertView.findViewById(R.id.checkList);
holder.checkGroup.setOnCheckedChangeListener(新建CompoundButton.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
如果(!isExpanded)
mListener.expandGroupEvent(groupPosition,isExpanded);
int getPosition=(整数)buttonView.getTag();
标题信息已选定(已检查);
如果(!已检查){
所选标题信息(假);
}
意向意向=新意向(上下文,AdapterHistoryExpandable.class);
intent.addFlags(intent.FLAG\u活动\u无\u动画);
背景。开始触觉(意图);
}
});
convertView.setTag(支架);
convertView.setTag(R.id.checkList,holder.checkGroup);
convertView.setTag(支架);
}否则{
holder=(ViewHolder)convertView.getTag();
}
holder.heading=(TextView)convertView.findViewById(R.id.heading);
holder.checkGroup.setTag(groupPosition);
holder.checkGroup.setOnCheckedChangeListener(新建CompoundButton.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
get(groupPosition).setSelected(buttonView.isChecked());
}
});
holder.checkGroup.setChecked(main.groupInfos.get(groupPosition.isSelected());
holder.heading.setText(headerInfo.getName().trim());
返回视图;
}
@凌驾
公共视图getChildView(最终整数组位置、最终整数子位置、布尔isLastChild、视图转换视图、视图组父级){
final ChildItemsInfo detailInfo=(ChildItemsInfo)getChild(groupPosition,childPosition);
最终持票人;
if(convertView==null){
LayoutInflater充气器=(LayoutInflater)main.getSystemService(Context.LAYOUT\u充气器\u服务);
convertView=充气机。充气(R.layout.list_历史,空);
holder=新的ViewHolder();
convertView.setTag(支架);
}否则{
holder=(ViewHolder)convertView.getTag();
}
holder.date=(TextView)convertView.findViewById(R.id.date_389;);
holder.h_ps_id=(TextView)convertView.findViewById(R.id.patient_id);
holder.h_ps_name=(TextView)convertView.findViewById(R.id.patient_);
holder.h_dokname=(TextView)convertView.findViewById(R.id.doctor_);
holder.h_item=(TextView)convertView.findViewById(R.id.item_);
holder.h\u数量=(TextView)convertView.findViewById(R.id.qty);
holder.h_service=(TextView)convertView.findViewById(R.id.servicetype_);
holder.checkChild=(复选框)convertView.findViewById(R.id.CheckBox);
ModelChecking add=新建ModelChecking();
if(main.groupInfos.get(groupPosition.isSelected()){
持有者c