Android ExpadableListView获取所选项目

Android ExpadableListView获取所选项目,android,expandablelistview,Android,Expandablelistview,如何使用多重选择模式在ExpandableListView中获取所有选定项 adapter = new ExpListAdapter(getActivity(), groups); expandableListView.setAdapter(adapter); adapter.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); expandableListView.setGroupIndicator(null); e

如何使用多重选择模式在ExpandableListView中获取所有选定项

 adapter = new ExpListAdapter(getActivity(), groups);
    expandableListView.setAdapter(adapter);
    adapter.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    expandableListView.setGroupIndicator(null);
    expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            adapter.setClicked(groupPosition, childPosition);
            int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
            parent.setItemChecked(index, true);
            return true;
        }
    });
选择所有项目后,我希望获得它们的ID或值,并提交下一个活动的意图。 和适配器

public class ExpListAdapter extends BaseExpandableListAdapter {
//////////

public void setClicked(int groupPosition, int childPosition) {
    SparseBooleanArray checkedChildPositionsMultiple = checkedPositions.get(groupPosition);
    // if in the group there was not any child checked
    if (checkedChildPositionsMultiple == null) {
        checkedChildPositionsMultiple = new SparseBooleanArray();
        // By default, the status of a child is not checked
        // So a click will enable it
        checkedChildPositionsMultiple.put(childPosition, true);
        checkedPositions.put(groupPosition, checkedChildPositionsMultiple);
    } else {
        boolean oldState = checkedChildPositionsMultiple.get(childPosition);
        checkedChildPositionsMultiple.put(childPosition, !oldState);
    }

    notifyDataSetChanged();
} 

使用以下代码段跟踪所有选中/选定的项目。您可能需要对此代码进行一些更改,但逻辑保持不变

if (save_state[position] == true) {
        viewHolder.check_box.setChecked(true);
    } else if (save_state[position] == false) {
        viewHolder.check_box.setChecked(false);
    }

    viewHolder.check_box.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (save_state[pos] == false) {
                save_state[pos] = true;
                selectedItemArray.add(populateList.get(pos));
                if (selectedItemArray.size() == populateList.size()) {
                    // all the item are checked/selected no
                }
            } else if (save_state[pos] == true) {
                save_state[pos] = false;
                selectedItemArray.remove(populateList.get(pos));
            }
        }
    });