Skip to content

Commit

Permalink
onHeaderLongClick
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Nov 1, 2014
1 parent 12e956a commit 97b92f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/src/se/emilsjolander/stickylistheaders/AdapterWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Checkable;
Expand All @@ -27,6 +28,7 @@ class AdapterWrapper extends BaseAdapter implements StickyListHeadersAdapter {

interface OnHeaderClickListener {
void onHeaderClick(View header, int itemPosition, long headerId);
boolean onHeaderLongClick(View header, int itemPosition, long headerId);
}

final StickyListHeadersAdapter mDelegate;
Expand Down Expand Up @@ -141,6 +143,17 @@ public void onClick(View v) {
}
}
});
header.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
if(mOnHeaderClickListener != null){
long headerId = mDelegate.getHeaderId(position);
return mOnHeaderClickListener.onHeaderLongClick(v, position, headerId);
}
return false;
}
});
return header;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class StickyListHeadersListView extends FrameLayout {
public interface OnHeaderClickListener {
void onHeaderClick(StickyListHeadersListView l, View header,
int itemPosition, long headerId, boolean currentlySticky);
boolean onHeaderLongClick(StickyListHeadersListView l, View header,
int itemPosition, long headerId, boolean currentlySticky);
}

/**
Expand Down Expand Up @@ -388,6 +390,15 @@ public void onClick(View v) {
mHeaderPosition, mHeaderId, true);
}
});
mHeader.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
return mOnHeaderClickListener.onHeaderLongClick(
StickyListHeadersListView.this, mHeader,
mHeaderPosition, mHeaderId, true);
}
});
}
mHeader.setClickable(true);
}
Expand Down Expand Up @@ -518,6 +529,14 @@ public void onHeaderClick(View header, int itemPosition, long headerId) {
headerId, false);
}

@Override
public boolean onHeaderLongClick(View header, int itemPosition,
long headerId) {
return mOnHeaderClickListener.onHeaderLongClick(
StickyListHeadersListView.this, header, itemPosition,
headerId, false);
}

}

private boolean isStartOfSection(int position) {
Expand Down Expand Up @@ -607,6 +626,15 @@ public void onClick(View v) {
mHeaderPosition, mHeaderId, true);
}
});
mHeader.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
return mOnHeaderClickListener.onHeaderLongClick(
StickyListHeadersListView.this, mHeader,
mHeaderPosition, mHeaderId, true);
}
});
}
} else {
mAdapter.setOnHeaderClickListener(null);
Expand Down

0 comments on commit 97b92f7

Please sign in to comment.