在第二次点击时仅调用textview上的Onclick事件(具有TextIsSelectable ="true") [英] Onclick event on textview(that has TextIsSelectable="true") is ony called on second click
问题描述
我在textview
上有一个onClickListener
,并且textview带有标记为selectable
.
但是,仅当第二次单击textview
时,才会调用我指定的onclick
事件.
第二次之后,它将调用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 this 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
.
如果我清楚地理解了您的问题,则您希望像普通的文本选择一样,在用户double taps
或long presses
时在文本视图中选择文本,但是当用户只需单击一次后,便希望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
.
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")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!