只有setOnItemClickListener

只有setOnItemClickListener

本文介绍了ListView的犯规火setOnLongClickListener,只有setOnItemClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个ListView这两个类型的点击 - 的onClick和LongClick

I'd like to have both type of clicks on a listView - onClick and LongClick.

我已经实现了它是这样的:

I've implemented it like this:

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) { ... } });

但它简化版,火长按。任何人有任何想法,为什么?

But it does't fire the Long Click.Anyone has any idea why?

推荐答案

u必须使longclickable

u have to enable the longclickable

list.setLongClickable(true);

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

}
});

这篇关于ListView的犯规火setOnLongClickListener,只有setOnItemClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:56