我在 textview
上有一个 onClickListener
,而 textview 的标志是它是 selectable
.但是我指定的 onclick
事件只有在 textview
被第二次点击时才会被调用.在第二次之后它调用 onclick 权限,但是如果另一个 textview
也是 selectable
与 onclicklistener
它也只被称为第二次时间,然后它工作正常,但另一个只工作第二次.我找不到这些奇怪事件的来源.
I have a onClickListener
on a textview
and the textview has the flag that it's selectable
.
But the onclick
event I specified is only called when the textview
is clicked a second time.
After the second time it calles the onclick right, but if a other textview
that also is selectable
with a onclicklistener
it also is only called the second time, then it works fine, but then the other one works only the second time again. I can't find the source of these weird events.
telefoonTXT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {startTelIntent();}}
);
urlTXT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {startWebIntent();}
});
我也遇到过这个问题.每当触摸文本视图时,首先onTouch
,然后是OnSelection
,最后是OnClick
.如果我清楚地理解您的问题,您想在用户 双击
或 long press
时选择文本视图中的文本,就像通常的文本选择一样,但是当用户只需单击它时,您想要onClick
功能.我认为以下内容可能会对您有所帮助.
I faced this issue as well. Whenever text view is touched firstly onTouch
, then OnSelection
and at last OnClick
is called.
If i understand your problem clearly you want to select text in text view when user double taps
or long presses
like the usual text selection but when user simply clicks it once u want the onClick
to function. I think the following might help you.
将 gestureDetector
添加到您的文本视图中.
Add a gestureDetector
to your text View.
GestureDetectorCompat mDetector;
mDetector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener());
mDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// This is where u add your OnClick event
startTelIntent();
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.d("dtttt", "double tap");
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
});
telefoonTXT.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mDetector.onTouchEvent(event);
return false;
}
});
这篇关于仅在第二次单击时调用 textview 上的 Onclick 事件(具有 TextIsSelectable=“true")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!