Android MotionEvent.ACTION\u在Textview上启动
我的文本视图不支持MotionEvent.Action\u UP。我在event.getAction上仅获得0 但同样的代码适用于ImageButton Textview不支持MotionEvent.Action\u UP吗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,
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,这意味着您没有处理该事件。就这样!请把它作为答案贴出来!