Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();}
});
like image 381
Wesley Egbertsen Avatar asked Oct 25 '13 08:10

Wesley Egbertsen


People also ask

How to extend an Android textview to a click event?

How to extend an Android TextView to a Click so that an event is triggered when you click on the text. To do this, you have to enter android:clickable="true" in the .xml page. And in the .java file assign an OnClickListener (..) Textfeld, Labelelement. In the activity_main.xml you have to expand the TextView element with clickable.

What is onClick event in JavaScript?

The onclick event generally occurs when the user clicks on an element. It allows the programmer to execute a JavaScript's function when an element gets clicked. This event can be used for validating a form, warning messages and many more. Using JavaScript, this event can be dynamically added to any element. It supports all HTML elements ...

How to change the text of a paragraph using onClick event?

Here we are using the onclick event with the paragraph element. When the user clicks on the paragraph element, the corresponding function will get executed, and the text of the paragraph gets changed. On clicking the <p> element, the background color, size, border, and color of the text will also get change.

How do I handle onclick events in this tiny app?

This tiny app contains 4 different buttons but we will only use a single function to handle the onClick events that fired when one of them clicked. The name of the clicked button will be displayed on the screen. We also call the preventDefault () method to prevent it from submitting the form.


Video Answer


1 Answers

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;
     }
});
like image 190
Frosty Avatar answered Oct 24 '22 21:10

Frosty