仅在第二次单击时调用 textview 上的 Onclick 事件

时间:2023-01-15
本文介绍了仅在第二次单击时调用 textview 上的 Onclick 事件(具有 TextIsSelectable=“true")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 textview 上有一个 onClickListener,而 textview 的标志是它是 selectable.但是我指定的 onclick 事件只有在 textview 被第二次点击时才会被调用.在第二次之后它调用 onclick 权限,但是如果另一个 textview 也是 selectableonclicklistener 它也只被称为第二次时间,然后它工作正常,但另一个只工作第二次.我找不到这些奇怪事件的来源.

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模板网!

上一篇:如何在我的 TextView 中以粗体和多色显示文本 下一篇:如果单词对于 textview 来说太长,则强制下一个单

相关文章

最新文章