ListView的长按菜单___源码分析
ListView的长按菜单___源码分析
Android的listview可以长按弹出来一个菜单。
今天就跟了下代码大概看了下弹出菜单的流程。
我们实现一个菜单长按步骤通常如下:
1.弹出菜单的生成
如果控制listview长按应该生成什么样的菜单。
a、生成一个OnCreateContextMenuListener的接口对象
该接口定义如下:在view.java中
private boolean performLongPress(final View child,final int longPressPosition, final long longPressId) { boolean handled = false; if (mOnItemLongClickListener != null) { handled = mOnItemLongClickListener.onItemLongClick(AbsListView.this, child, longPressPosition, longPressId); } if (!handled) { mContextMenuInfo = createContextMenuInfo(child, longPressPosition, longPressId); handled = super.showContextMenuForChild(AbsListView.this); } if (handled) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } return handled; } ContextMenuInfo createContextMenuInfo(View view, int position, long id) { return new AdapterContextMenuInfo(view, position, id); } ContextMenuInfo createContextMenuInfo(View view, int position, long id) { return new AdapterContextMenuInfo(view, position, id); }