1
如何獲取ExpandableListView中所有選擇的項目與乘法選擇模式?ExpadableListView獲取選定的項目android
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();
}