gpt4 book ai didi

android - ListView 不触发 setOnLongClickListener,只触发 setOnItemClickListener

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:06:53 27 4
gpt4 key购买 nike

我希望对 listView 进行两种类型的点击 - onClick 和 LongClick。

我是这样实现的:

this.listViewSub = (ListView) this.findViewById(R.id.listsub);

this.listViewSub.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView parent, final View view, final int position,
final long id) { ... } });

// listen to long click - to share texts
this.listViewSub.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) { ... } });

但它不会触发长按。有人知道为什么吗?

最佳答案

您必须启用LongClickable

list.setLongClickable(true);

list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {

}
});

关于android - ListView 不触发 setOnLongClickListener,只触发 setOnItemClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6607479/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com