Skip to content

Commit

Permalink
Add longPress support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raúl Pedro Fernandes Santos authored and Paul Soucy committed Oct 5, 2011
1 parent 658a3a8 commit 777e0f0
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions devsmartlib/src/com/devsmart/android/ui/HorizontalListView.java
Expand Up @@ -57,6 +57,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
private Queue<View> mRemovedViewQueue = new LinkedList<View>();
private OnItemSelectedListener mOnItemSelected;
private OnItemClickListener mOnItemClicked;
private OnItemLongClickListener mOnItemLongClicked;
private boolean mDataChanged = false;


Expand Down Expand Up @@ -86,6 +87,11 @@ public void setOnItemClickListener(AdapterView.OnItemClickListener listener){
mOnItemClicked = listener;
}

@Override
public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener) {
mOnItemLongClicked = listener;
}

private DataSetObserver mDataObserver = new DataSetObserver() {

@Override
Expand Down Expand Up @@ -354,8 +360,27 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
return true;
}



@Override
public void onLongPress(MotionEvent e) {
Rect viewRect = new Rect();
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
int left = child.getLeft();
int right = child.getRight();
int top = child.getTop();
int bottom = child.getBottom();
viewRect.set(left, top, right, bottom);
if (viewRect.contains((int) e.getX(), (int) e.getY())) {
if (mOnItemLongClicked != null) {
mOnItemLongClicked.onItemLongClick(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i));
}
break;
}

}
}

};


Expand Down

0 comments on commit 777e0f0

Please sign in to comment.