Onclick event on textview(that has TextIsSelectable=“true”) is ony called on second click

前端 未结 3 1262
情话喂你
情话喂你 2021-02-07 11:48

I have a onClickListener on a textview and the textview has the flag that it\'s selectable. But the onclick event I specified

相关标签:
3条回答
  • 2021-02-07 12:04

    I Just Used in TextView Xml :

    android: TextIsSelectable="true" 
    android: clickable="true"
    

    and worked fine for me. First Single Tap called the onclick event, And Anytime LongClick Select the text. And Double tap called the two method at a time. But, In my case this was no problem, this was worked for me for calling onclick and select the text as well at a time Without using a bunch of code.
    One bonus thing, It works fine also in adapter and recycler view as well.

    0 讨论(0)
  • 2021-02-07 12:09

    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.

    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;
         }
    });
    
    0 讨论(0)
  • 2021-02-07 12:11

    set this ...

    TextisSelectable = "false"
    

    i think it will be work correctly

    0 讨论(0)
提交回复
热议问题