禁用ListView项的听众 [英] Disable ListView Item's listeners

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

问题描述

我有不同类型的行一个ListView。该行可能包含文字,图片,视频或其他什么东西。如果我点击的ImageView(行内)我会去另一个活动来显示图像全屏,如果我的视频点击(行内)我会去另一个活动中发挥他的视频。

I have a ListView with different types of rows. The row may contain text, image, video or something else. If I click on ImageView (inside the row) I will go to another activity to show the image in full screen, If I click on Video (inside the row) I will go to another activity to play he video.

我已经正确实施向左轻扫听众对我的ListView。如果我在ListView中的空白区域开始的ListView刷卡,刷一下工作(在下面的图像的第一和第二行)。但是,如果我开始从ListView控件行的项目在ListView轻扫,然后刷卡不工作(在下面的图像第三和第四行)。如果我删除的ImageView和视频的点击事件,然后轻扫工程,即使我开始从ListView控件行的项目即刷卡在这种情况下,刷卡作用于整个ListView的,不管在哪一行我做的刷卡。

I have implemented right to left swipe listener on my ListView. If I start the ListView swipe from an empty space in ListView, the swipe works (first and second row in below image). However if I start the ListView swipe from the ListView row's item, then the swipe doesn't work (third and fourth row in below image). If I remove the click events from ImageView and Video then the swipe works even if I start the swipe from the ListView row's item i.e. in this case the swipe works on whole ListView, no matter on which row I do the swipe.

在这里输入的形象描述

我怎样才能摆脱对这个问题?我认为这是可以,如果我禁用内部ListView中所有项目的所有点击事件来实现。怎么可以这样做?有没有其他办法?

How can I get rid on this problem? I think this can be achieved if I disable all the click events on the all the items inside ListView. How can do so? Is there any other way?

我想要的ListView都刷卡,然后点击ListView的项目。

I want both swipe on ListView and click on ListView's item.

推荐答案

招数办法,你可以调用ListView的onTouchListener的项目,被点击的图像或视频时。只需拨打的ImageView onTouch方法。

Trick way, you can call item of listview's onTouchListener, when the Image or Video was clicked. Simply call imageview's onTouch method.

ImageView image; // your image view, and asuume the it is initialized.

row.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction()) {

    case MotionEvent.ACTION_DOWN:                     
        image.onTouchEvent(event);
        break;                     
    }

    return false;
}

});

,看来,你的图像或视频有它自己的onTouchListener。问题是,它们消耗事件和它的父视图不给他们。所以,不要返回真实,然后该事件将被发送到它的父。

OR, It seems that, your image or video has it's own onTouchListener. The problem is, they consume the event and do not send them to it's parent view. So, do not return "true", and the event will be sent to it's parent.

这篇关于禁用ListView项的听众的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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