tjerkw / Android-SlideExpandableListView

A better ExpandableListView, with animated expandable views for each list item
Apache License 2.0
1.98k stars 741 forks source link

How to close the expanded view? #29

Closed shawnlinboy closed 11 years ago

shawnlinboy commented 11 years ago

Hi, Thanks for creating this library.It works well with my app. I just added a button for deleting a listitem in the expandable view.However,as i clicked the button,the listitem can be deleted correctly, but the next listitem's expandable view will be expanded automaticlly,how to solve this problem?

JesseFarebro commented 11 years ago

Use

collapseLastOpen(); // Returns true if an item was collapsed false otherwise

Before deleting the list item. You can as well check if any item is expanded by using

isAnyItemExpanded(); // Returns a boolean if there is any item expanded

If you want to make the transition a little more smooth post a delayed handler for the duration of the animation then remove the item as such:

if(collapseLastOpen()) {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
            removeMyListItem(position);
        }, mAdapter.getAnimationDuration() );
} else {
    removeMyListItem(position);
}

Also please look into the library a little more to figure out your solution next time. Hope this helps.

shawnlinboy commented 11 years ago

Got my problem solved. THX!