Control onclicklistener in autolink enabled textview

前端 未结 9 2648
一向
一向 2020-12-08 19:13

I am using a TextView for which I have set autolink=\"web\" property in XML file. I have also implemented the onClickListener for this TextView. Th

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 19:45

    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 
            }
        }
    });
    

    It may be a late reply, but may be useful to those who are searching for a solution.

提交回复
热议问题