控制onclicklistener在自动链接启用的TextVie

控制onclicklistener在自动链接启用的TextVie

本文介绍了控制onclicklistener在自动链接启用的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的,我已经在XML文件中设置自动链接=网络属性,一个TextView。我还实施了onClickListener这个TextView的。问题是,当TextView的文本包含一个超链接,如果我碰那个链接,该链接在浏览器中打开,但同时onClickListener触发了。我不希望出现这种情况。

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. The problem is, when the text in TextView contains a hyperlink, and if I touch that link, the link opens in browser but simultaneously the onClickListener triggers too. I don't want that.

我想,如果我触摸超链接的clickListener不应该解雇。它应该只火,如果我碰那个是不是超链接文本的一部分。任何建议?

What I want is, if I touch the hyperlink the clickListener should not fire. It should only fire if I touch the part of the text that is not hyperlinked. Any suggestion?

推荐答案

您可以在getSelectionStart()和getSelectionEnd()TextView的类函数周围使用作品达到这个目的,

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.

这篇关于控制onclicklistener在自动链接启用的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 02:17