@Override public void onLongPress(MotionEvent e) { Rect viewRect = new Rect(); for (int i = 0; i < getChildCount(); 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 (mOnItemLongClickListener != null) { mOnItemLongClickListener.onItemLongClick( HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i)); } if (mOnItemSelected != null) { mOnItemSelected.onItemSelected( HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i)); } break; } } }
/** * This method will be called when an item has been long clicked. * * @param parent The parent view of the clicked item. * @param view The long clicked item. * @param position The position in the list, that has been clicked. * @param id The id of the clicked item. * @return Whether the click has been handled by the wrapper. */ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // If choice mode is none, just notify the original listener. // TODO: CHOICE_MODE_SINGLE, how is it handled in android native? if (getChoiceMode() == CHOICE_MODE_NONE || getChoiceMode() == CHOICE_MODE_SINGLE) { if (listener != null) { return listener.onItemLongClick(parent, view, position, id); } else { return false; } } else if (getChoiceMode() == CHOICE_MODE_MULTIPLE && multiChoiceListener != null) { // Start actionmode on the parent SherlockActivity if (actionmode == null) { actionmode = ABSListView.this.startActionMode(multiChoiceListener); } // Check the item and inform the MultiChoiceModeListener ABSListView.this.setItemChecked(position, !((Checkable) view).isChecked()); multiChoiceListener.onItemCheckedStateChanged( actionmode, position, id, ((Checkable) view).isChecked()); return true; } return false; }
@Override public boolean onItemLongClick(AdapterView<?> l, View v, int position, long id) { if (onItemLongClickListenerDelegate != null) { return onItemLongClickListenerDelegate.onItemLongClick( l, v, adapter.translateListViewPosition(position), id); } return false; }
@Override public void onLongPress(MotionEvent e) { int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (isEventWithinView(e, child)) { if (mOnItemLongClicked != null) { mOnItemLongClicked.onItemLongClick( HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i)); } break; } } }
@Override public void onLongPress(MotionEvent e) { unpressTouchedChild(); final int index = getChildIndex((int) e.getX(), (int) e.getY()); if (index >= 0 && !mBlockTouchAction) { View child = getChildAt(index); OnItemLongClickListener onItemLongClickListener = getOnItemLongClickListener(); if (onItemLongClickListener != null) { int adapterIndex = mLeftViewAdapterIndex + index; boolean handled = onItemLongClickListener.onItemLongClick( HorizontalListView.this, child, adapterIndex, mAdapter.getItemId(adapterIndex)); if (handled) { // BZZZTT!!1! performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } } } }
protected boolean fireOnItemLongClick(final int position, final View v) { if (onItemLongClickListener != null) return onItemLongClickListener.onItemLongClick(this, v, position, v.getId()); return false; }