I am passing arraylist to my expandable list adapter. when i delete an element from the specific location in arraylist and then notifies the adapter with notifyDataSetChanged(), i am not getting correct state of grp in expandable list view.
For Ex:
1 - My arraylist is having 5 elements and adaper is displaying 5 view on display.
2 - Initially all the groups will be in collapsed state.
3 - i am expanding first group. [grp 1 - expanded, grp 2 - collapsed, grp 3 - collapsed, grp 4 - collapsed, grp 5 - collapsed].
4 - now i am deleting first grp. After deleting, my arraylist will have 4 elements and grp 2 becomes grp1, grp 3 becomes grp 2 and so on.
5 - After deleting, the correct state of grp shd be [grp 1 - collapsed, grp 2 - collapsed, grp 3 - collapsed, grp 4 - collapsed], but instead of this i am getting, the state of the grp is [grp 1 - expanded, grp 2 - collapsed, grp 3 - collapsed, grp 4 - collapsed].
why the hell grp 1 (prev it was grp 2) got expanded??? it should be in collapsed state.
I think this is very small issue but i am unable to find solution. Kindly suggest solution. Early reply from anyone will be highly appreciated.
When you call notifyDataSetChanged()
, you let the adapter know that the data has changed, but it doesn't tell anything about the views. So adapter remembers that the first group is expanded and when you notify the adapter of changes it takes the new data and fills the ExpandableListView
with it, thus keeping the first group expanded.
A solution would be to manually control which groups are expanded, see here (look at restoring the state): https://stackoverflow.com/a/10905158/2197087