I am trying to delete Group when selected in my Expandable List and having the list refreshed after the delete occurred.
I took the source code from
Add the functionality to your Adapter to remove an Item:
public void removeGroup(int group) {
//TODO: Remove the according group. Dont forget to remove the children aswell!
Log.v("Adapter", "Removing group"+group);
notifyDataSetChanged();
}
public void removeChild(int group, int child) {
//TODO: Remove the according child
Log.v("Adapter", "Removing child "+child+" in group "+group);
notifyDataSetChanged();
}
Make sure the new methods are accessible to you by changing:
ExpandableListAdapter mAdapter;
to
MyExpandableListAdapter mAdapter;
Call the methods when needed:
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
String title = ((TextView) info.targetView).getText().toString();
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
mAdapter.removeChild(groupPos, childPos);
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
mAdapter.removeGroup(groupPos);
return true;
}
return false;
}
So, hope that helps. Cheers