android ClickableSpan intercepts the click event

前端 未结 5 995
慢半拍i
慢半拍i 2021-02-01 15:42

I have a TextView in a Layout. It\'s so simple. I put a OnClickListener in the layout and some part of the TextView is set to be ClickableSpan. I want the ClickableSpan to do s

5条回答
  •  情话喂你
    2021-02-01 16:31

    Here is an easy solution and it worked for me

    You can achieve this using a work around in getSelectionStart() and getSelectionEnd() functions of the Textview class,

    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClassroomLog.log(TAG, "Textview Click listener ");
            if (tv.getSelectionStart() == -1 && tv.getSelectionEnd() == -1) {
                //This condition will satisfy only when it is not an autolinked text
                //Fired only when you touch the part of the text that is not hyperlinked 
            }
        }
    });
    

提交回复
热议问题