Skip to content

Commit

Permalink
Added OnItemExpandCollapseListener code to AbstractSlideExpandableLis…
Browse files Browse the repository at this point in the history
…tAdapter
  • Loading branch information
reisub authored and tjerkw committed Jan 10, 2014
1 parent 351ed19 commit 40d8c99
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,63 @@ public AbstractSlideExpandableListAdapter(ListAdapter wrapped) {
}
}

private OnItemExpandCollapseListener expandCollapseListener;

/**
* Sets a listener which gets call on item expand or collapse
*
* @param listener
* the listener which will be called when an item is expanded or
* collapsed
*/
public void setItemExpandCollapseListener(
OnItemExpandCollapseListener listener) {
expandCollapseListener = listener;
}

public void removeItemExpandCollapseListener() {
expandCollapseListener = null;
}

/**
* Interface for callback to be invoked whenever an item is expanded or
* collapsed in the list view.
*/
public interface OnItemExpandCollapseListener {
/**
* Called when an item is expanded.
*
* @param itemView
* the view of the list item
* @param position
* the position in the list view
*/
public void onExpand(View itemView, int position);

/**
* Called when an item is collapsed.
*
* @param itemView
* the view of the list item
* @param position
* the position in the list view
*/
public void onCollapse(View itemView, int position);

}

private void notifiyExpandCollapseListener(int type, View view, int position) {
if (expandCollapseListener != null) {
if (type == ExpandCollapseAnimation.EXPAND) {
expandCollapseListener.onExpand(view, position);
} else if (type == ExpandCollapseAnimation.COLLAPSE) {
expandCollapseListener.onCollapse(view, position);
}
}

}


@Override
public View getView(int position, View view, ViewGroup viewGroup) {
this.parent = viewGroup;
Expand Down Expand Up @@ -220,6 +277,9 @@ public void onAnimationRepeat(Animation animation) {
if (lastOpenPosition != -1 && lastOpenPosition != position) {
if (lastOpen != null) {
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE);
notifiyExpandCollapseListener(
ExpandCollapseAnimation.COLLAPSE,
lastOpen, lastOpenPosition);
}
openItems.set(lastOpenPosition, false);
}
Expand All @@ -229,6 +289,7 @@ public void onAnimationRepeat(Animation animation) {
lastOpenPosition = -1;
}
animateView(target, type);
notifiyExpandCollapseListener(type, target, position);
}
}
});
Expand Down

0 comments on commit 40d8c99

Please sign in to comment.