如何处理长按上ListView项?如何处理、按上、ListView

2023-09-08 08:47:26 作者:姐有姐的feel

我怎么能赶上这样的活动吗? 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:

添加AdapterView.OnItemLongClickListener.请参阅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
  }
});

如果您要创建一个自定义的适配器,添加一个View.OnLongClickListener创建视图的方法Adapter#getView(...)

if you are creating a custom adapter, add a View.OnLongClickListener when creating the View in the method Adapter#getView(...)