Ich kenne ähnliche Frage vor, aber sie können mein Problem nicht lösen.Get Checkbox-Wert von expandableview
Ich erstelle eine check box expandable view
, deren Daten von einigen Api stammen. Jetzt möchte ich alle ausgewählten Kontrollkästchen Wert in meiner Aktivität.
Nun bekomme ich alle Werte (ich verweise eine andere Frage Expandable check box) und ich habe diesen Wert als Rückgabe ([Pair{4 4}, Pair{3 3}, Pair{0 0}, Pair{3 6}, Pair{1 5}, Pair{3 7}, Pair{4 3}, Pair{3 4}, Pair{1 6}, Pair{4 2}, Pair{3 5}]
). Wie könnte ich nun Wert von diesem Wert bekommen?
private final Set<Pair<Long, Long>> mCheckedItems = new HashSet<Pair<Long, Long>>();
Und
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.expandable_group_child, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.expandableChild);
final CheckBox cb = (CheckBox) convertView.findViewById(R.id.childCkBox);
// add tag to remember groupId/childId
final Pair<Long, Long> tag = new Pair<Long, Long>(
getGroupId(groupPosition),
getChildId(groupPosition, childPosition));
cb.setTag(tag);
// set checked if groupId/childId in checked items
cb.setChecked(mCheckedItems.contains(tag));
// set OnClickListener to handle checked switches
cb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final CheckBox cb = (CheckBox) v;
final Pair<Long, Long> tag = (Pair<Long, Long>) v.getTag();
if (cb.isChecked()) {
mCheckedItems.add(tag);
//mCheckBoxData.put(getGroupId(groupPosition),
getChildId(groupPosition, childPosition));
} else {
mCheckedItems.remove(tag);
//mCheckBoxData.remove(getGroupId(groupPosition),getChildId(groupPosition, childPosition));
}
}
});
txtListChild.setText(childText);
return convertView;
}
in Activity ->
private Set<Pair<Long, Long>> mCheckedItems = new HashSet<Pair<Long, Long>>();
mCheckedItems = listAdapter.getCheckedItems();
System.out.println(mCheckedItems);
Ich weiß jetzt, wie die Daten aus dieser Art retrive. Jeder Vorschlag und jede Bearbeitung ist willkommen.
Edit: Ich habe mehrere Gruppen und alle Daten kommen durch Api.
Sie Schnittstelle für das verwenden können .. – gaurang
@gaurang Wie das verwenden ... .. – Vivek