项目在ListView控件不长在点击设置getView点击监听后() [英] Items in ListView not long clickable after setting click listener in getView()

查看:212
本文介绍了项目在ListView控件不长在点击设置getView点击监听后()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已搜索周围,并没有一个解决方案出来了(也许没有使用正确的关键字)。

I've searched around and have not come out with a solution (maybe not using the correct keywords).

所以,我该项目时长单击其项目可以上拖动一个自定义的ListView。在它的项目,有一个ImageView的和的LinearLayout包含两个TextViews。在单击的LinearLayout或ImageView的动作时完成。

So, I've a custom ListView which its item can be dragged around when the item is long clicked. Within its item, there's an ImageView and LinearLayout containing two TextViews. Actions are done when the LinearLayout or ImageView is clicked.

要做到这一点,我已经在我的DragListView延伸的ListView,开始拖动操作,并onInterceptTouchEvent管理拖动操作。使用setOnItemLongClickListener

To do this, I've use setOnItemLongClickListener on my DragListView which extends ListView, to initiate drag action, and onInterceptTouchEvent to manage the drag action.

然后,我已经建立扩大BaseAdapter的自定义适配器overrided其getView()来实现的行中的子项。在的LinearLayout和ImageView的已经setOnClickListener。

Then, I have built a custom adapter extending BaseAdapter and overrided its getView() to implement the child items in the row. The LinearLayout and ImageView have been setOnClickListener.

问题是,在的LinearLayout和ImageView的是能够做自己的东西,但onItemLongClick不叫。

The problem is, the LinearLayout and ImageView are able to do their stuff, but the onItemLongClick isn't called.

里面getView()监听;

The listener inside getView();

    holder.delete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
//Do something
}

有关项目长按(拖动启动)

For item long click (drag initiator)

setOnItemLongClickListener(new OnItemLongClickListener() {              

    @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view,
                        int position, long id) {
    //Do something
    }

非常感谢你!

推荐答案

我认为,一个手势检测器的方法来处理事件之一。
然而,通常,一个手势检测器用于当我们想要检测的姿势不长preSS

I think that a gesture detector is one of ways to handle events. Usually, however, a gesture detector is used when we want to detect a gesture not a long-press.

为什么onItemLongClick不叫的原因是,onClickListener可能会消耗触摸事件。
在这个原因,如果你想处理onItemLongClick,拦截触摸事件,并分派到的意见要处理。

The reason why onItemLongClick isn't called is that onClickListener might consume a touch event. In that reason, if you want to handle onItemLongClick, intercept touch event and dispatch it to views you want to handle.

您可以找到下面的链接了解详情。
http://developer.android.com/guide/topics/ui/ui -events.html

You can find more details following link. http://developer.android.com/guide/topics/ui/ui-events.html

这篇关于项目在ListView控件不长在点击设置getView点击监听后()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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