Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MotionEvent.ACTION\u在Textview上启动_Android_Textview_Listener_Mouseevent - Fatal编程技术网

Android MotionEvent.ACTION\u在Textview上启动

Android MotionEvent.ACTION\u在Textview上启动,android,textview,listener,mouseevent,Android,Textview,Listener,Mouseevent,我的文本视图不支持MotionEvent.Action\u UP。我在event.getAction上仅获得0 但同样的代码适用于ImageButton Textview不支持MotionEvent.Action\u UP吗 textView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View v,

我的文本视图不支持MotionEvent.Action\u UP。我在event.getAction上仅获得0

但同样的代码适用于ImageButton

Textview不支持MotionEvent.Action\u UP吗

   textView.setOnTouchListener(new OnTouchListener() {    
                @Override
                public boolean onTouch(final View v, final MotionEvent event) {
                    Log.v("tag","textView"+event.getAction());
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        Log.v("tag","textViewmousedown");
                    } else if(event.getAction() == MotionEvent.ACTION_UP) {
                        //This gets never called
                        Log.v("tag","textViewmouseup");
                        if (standardButtonClickListener != null) {
                            standardButtonClickListener.onStandardButtonClick(v);
                        }
                    }
                    return false;
                }
            });

您必须在
onTouch
方法中返回
true
,而不是
false
。这样,进一步的事件将传递给您的侦听器。

不要忘记MotionEvent.ACTION\u取消

 @Override
    public boolean onTouch(final View view, final MotionEvent motionEvent) {

        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                setColorFilter(Color.argb(155, 185, 185, 185));
        }
        else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                setColorFilter(Color.argb(0, 185, 185, 185));

        }
        return false;
    }

安卓系统上没有鼠标这回事。
UP
事件意味着用户按下了UP按钮(通常在D-PAD或轨迹球上)。我指的是MotionEvent.ACTION\u元素,当你松开手指时,尝试返回true而不是false。可能它没有在
关闭后发送进一步的事件,因为您返回了false,这意味着您没有处理该事件。就这样!请把它作为答案贴出来!