Reputation: 21237
I have a clickListener inside of the getChildView of an ExpandableListView. When the user clicks on one of the children, that row is removed from the list. I need to refresh the list view to reflect this deletion. Since I am inside of the data adapter, I don't think that I can call notifyDataSetChanged() as I would if I were insider of the Activity where I set the adapter.
I know that I can start a new Activity, but this adds a nearly exact duplicate to the activity stack (and possibly many of them). I'm looking for a way to refresh this list without calling startActivity. If I manually collapse and expand the group, the list refreshes, so i tried to do this programatically, but that's not working either. (note that the group that I am refreshing is always at position 1).
Does anyone know how can I refresh this list view without starting a new activity? Thanks!
public class ExpandListAdapter extends BaseExpandableListAdapter {
public ExpandListAdapter(Context context, ArrayList<ExpandListGroup> groups, ExpandableListView expandableList) {
this.context = context;
this.groups = groups;
this.expandableList = expandableList;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, final ViewGroup parent) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//call method to remove this item from the database
//remove item from ArrayList
//refresh the view -- this is where I am stuck
//tried expandableList.collapseGroup(1); but null pointer resulted
}
}
}
}
Upvotes: 0
Views: 112