zoukankan      html  css  js  c++  java
  • android 长按 ListView 无法弹出 ContextMeun

    可能的原因:

    onItemLongClick 消费了长按事件

    1. mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    2. @Override
    3. public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    4. mApSelect = position;
    5. Log.d(TAG, "onItemLongClick:" + mApSelect);
    6. return false;
    7. }
    8. });
    关键在 onItemLongClick 函数的返回值,看文档注释:
    1. /**
    2. * Callback method to be invoked when an item in this view has been
    3. * clicked and held.
    4. *
    5. * Implementers can call getItemAtPosition(position) if they need to access
    6. * the data associated with the selected item.
    7. *
    8. * @param parent The AbsListView where the click happened
    9. * @param view The view within the AbsListView that was clicked
    10. * @param position The position of the view in the list
    11. * @param id The row id of the item that was clicked
    12. *
    13. * @return true if the callback consumed the long click, false otherwise
    14. */
    如果返回 ture,系统认为用户实现的回调函数已经处理完了长按事件。而弹出 ContextMenu 也是长按事件的响应,且在 onItemLongClick 响应之后,所以返回 true 导致 ContextMenu 无法弹出。




  • 相关阅读:
    Linux Shell 基本语法
    VIM选择文本块/复制/粘贴
    linux vi命令详解2
    SSH命令详解2
    JAVA调用Shell脚本
    scp命令的用法详解
    Java实践 — SSH远程执行Shell脚本
    Remote SSH: Using JSCH with Expect4j
    c++内置函数---7
    c++将引用作为函数的参数---6
  • 原文地址:https://www.cnblogs.com/JonnyLulu/p/4462642.html
Copyright © 2011-2022 走看看