长按ListFragment
我正在使用 ListFragment 并执行 onListItemClick。一切正常,但现在我想使用长项目单击(例如 setOnItemLongClickListener(new OnItemLongClickListener() for an Activity)。我如何在我的片段中使用它?
谢谢!
I'm working with a ListFragment and doing a onListItemClick. Everything works fine, but now I want to use a long Item Click (e.g setOnItemLongClickListener(new OnItemLongClickListener() for an Activity). How can I use this in my fragment?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,tsync 发布的解决方案对我有用。我也遇到了同样的问题并认为这是不可能的。我尝试了上述建议,如下:
并且成功了!
Yes, the solution posted by tsync works for me. I too had ran into same problem and considered that this is not possible. I tried the above suggestion as follows:
and it worked!
根据您想要实现的内容,您可以对上下文菜单使用给定的方法:
首先注册长按的 View 类(在 Fragment 类中):
然后实现这两个方法,创建上下文菜单并执行您想要的操作单击菜单项时:
Depending on what you want to realize you can use the given methods for context menues:
First register the View class which gets long pressed (inside your Fragment class):
Than implement these two methods, to create a context menu and do what ever you want when a menu item is clicked:
这对我有用
This works for me
有点晚了,但我最近遇到了片段中上下文菜单的问题。菜单会加载,但只会加载一个弹出浮动菜单,没有图标等。上面的答案帮助我指明了正确的方向。
因此,经过一些尝试和错误,我用以下方法解决了这个问题:
在 onItemSelected:
这解决了问题,现在当我长按一个项目时,会显示带有图标的完整上下文菜单,并且浮动弹出菜单消失了。
Bit late on this but i recently had an issue with the context menu in a fragment. The menu would load but only a popup floating menu with no icons etc.. The answer above helped point me in the right direction.
So with a bit of trial and error i resolved it with this:
And in onItemSelected:
This solved the issue, now when i long click an item the full context menu with icons is displayed and the floating popup menu has gone.