問題描述
我在 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模板網!