Je souhaite récupérer l'élément de données sélectionné dans la liste de sélection non réutilisable. J'ai d'abord obtenu tous les éléments que je les ai sélectionnés ou non ... mais je ne suis pas en mesure d'obtenir les éléments sélectionnés. et affichez-les en tant que parents avec ses enfants.Liste des éléments sélectionnés dans la liste des consommables
public class CategoryBaseAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<ProfessionEntity> _listDataHeader;
public static HashMap<ProfessionEntity, List<ProfessionChildEntity>> _listDataChild;
public static HashMap<Integer, boolean[]> mChildCheckStates;
private Map<ProfessionEntity, List<ProfessionChildEntity>> selectedItems;
public CategoryBaseAdapter(Context context,
List<ProfessionEntity> listDataHeader,
HashMap<ProfessionEntity, List<ProfessionChildEntity>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
selectedItems = new HashMap<ProfessionEntity,List<ProfessionChildEntity>>();
}
public Map<ProfessionEntity, List<ProfessionChildEntity>> getSelectedItems() {
return selectedItems;
}
public boolean isSelected(int groupPosition, int childPosition){
ProfessionEntity group = _listDataHeader.get(groupPosition);
ProfessionChildEntity child = getChild(groupPosition,childPosition);
List<ProfessionChildEntity> sel = selectedItems.get(group);
return sel != null && sel.contains(child);
}
public void toggleSelection(int groupPosition, int childPosition){
ProfessionEntity group = _listDataHeader.get(groupPosition);
ProfessionChildEntity child = getChild(groupPosition,childPosition);
List<ProfessionChildEntity> sel = selectedItems.get(group);
if (sel == null){
sel = new ArrayList<ProfessionChildEntity>();
selectedItems.put(group, sel);
}
if (sel.contains(child))
sel.remove(child);
else
sel.add(child);
}
@Override
public ProfessionChildEntity getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final int mGroupPosition = groupPosition;
final int mChildPosition = childPosition;
final String childText = getChild(groupPosition, childPosition)
.getDescription();
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_item, null);
}
final CheckBox childCheckBox = (CheckBox) convertView
.findViewById(R.id.childCheckBox);
TextView txtListChild = (TextView) convertView
.findViewById(R.id.childTextView);
txtListChild.setText(childText);
childCheckBox.setOnCheckedChangeListener(null);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public ProfessionEntity getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = getGroup(groupPosition).getDecription();
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.groupTextView);
CheckBox grpCheckBox = (CheckBox) convertView
.findViewById(R.id.groupCheckBox);
grpCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Log.d("grp clicked", "grpCheckBox");
}
});
lblListHeader.setText(headerTitle);
grpCheckBox.setTag(convertView);
if (isExpanded) {
Log.d("abc", "abc");
} else {
Log.d("abc", "abc");
}
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Vous devez utiliser la HashMap avec consiste sa valeur mère et la valeur qui sont sélectionnés dans l'enfant –
comment gérer les sélections aléatoires –
En ce qui concerne le parent de l'élément sélectionné ... vous devez gérer cela ... Dans la méthode getChildView ... vous devez faire l'écouteur onclick et le gérer –