如何处理长按上ListView项? [英] How to handle long tap on ListView item?

查看:99
本文介绍了如何处理长按上ListView项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能赶上这样的活动吗? onCreateContextMenu 相当similiar,但我不需要的菜单。

How can I catch such event? onCreateContextMenu is quite similiar, but I don't need menu.

推荐答案

这是很难知道你需要什么来实现的。但我的猜测是,你想通过接收长按该项目执行一些acion。对于这一点,你有两个选择:

It's hard to know what you need to achieve. But my guess is that you want to perform some acion over the item that receives the long click. For that, you have two options:

  • 添加<一href="http://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html">AdapterView.OnItemLongClickListener.请参阅<一href="http://developer.android.com/reference/android/widget/AdapterView.html#setOnItemLongClickListener%28android.widget.AdapterView.OnItemLongClickListener%29">setOnItemLongClickListener.
  • add an AdapterView.OnItemLongClickListener. See setOnItemLongClickListener.

listView.setOnItemLongClickListener (new OnItemLongClickListener() {
  public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
    //do your stuff here
  }
});

  • 如果您要创建一个自定义的适配器,添加一个<一个href="http://developer.android.com/reference/android/view/View.OnLongClickListener.html">View.OnLongClickListener创建视图的方法<一个时href="http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29">Adapter#getView(...)
    • if you are creating a custom adapter, add a View.OnLongClickListener when creating the View in the method Adapter#getView(...)
    • 这篇关于如何处理长按上ListView项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆