安卓:: OnTouchListener和放大器;&安培; OnClickListener组合问题 [英] Android :: OnTouchListener && OnClickListener combination issue

查看:124
本文介绍了安卓:: OnTouchListener和放大器;&安培; OnClickListener组合问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述:

我有一个的TextView RelativeLayout的,我想,当用户触摸它来颜色故红色,转到另一页上,当他点击它。 于是,我就设置 OnClickListener 做的点击,和 OnTouchListener 来实现触摸功能( MotionEvent.ACTION_DOWN ),但这种组合是不行的,因为 OnTouchListener OnClickListener 非功能性(不知道为什么)。

I have a TextView on a RelativeLayout and I want to color it red when the user touches it, and go on another page when he clicks on it. So I tried to set an OnClickListener to do the click, and an OnTouchListener to implement the touch function (MotionEvent.ACTION_DOWN) but this combination doesn't work, because OnTouchListener makes OnClickListener non-functional (don't know why).

在论坛上的人说,我们可以实现的OnClick 由OnTouch MotionEvent.ACTION_UP ,但是这一次能触发了我的的TextView 布局(TextView的会被点击,如果你preSS并拖动你的手指在他外面释放),这是不期望的行为因为我想:
     点击= preSS +释放的TextView的。

On forums people say that we can implement the OnClick by the OnTouch MotionEvent.ACTION_UP, but this one can be triggered out of my TextView layout (the TextView gonna be clicked if you press it and drag your finger out of him to release) and this is not the desired behavior because I want:
click = press + release on the TextView.

有人可以给我一个解决方案,这个好吗?

Can someone give me a solution for this please?

推荐答案

您可以致电View.performClick(当action_up)。希望它能帮助。

you may call View.performClick() when action_up. Hope it helps.

your_txtView.setOnClickListener(new TextView.OnClickListener(){
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });

    your_txtView.setOnTouchListener(new TextView.OnTouchListener(){
            @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (MotionEvent.ACTION_DOWN == event.getAction()) {

        } else if (MotionEvent.ACTION_UP == event.getAction()) {
            v.performClick();
        }

        return true;
    }
    });

这篇关于安卓:: OnTouchListener和放大器;&安培; OnClickListener组合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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