其他分享
首页 > 其他分享> > 在文本视图android中的每个字符串上有多个onclicklistener

在文本视图android中的每个字符串上有多个onclicklistener

作者:互联网

我想在文本视图中添加多个可点击链接!获得每个单击文本的响应.

As show in the attached images blue text are click able.these links does not have fixed position in string.

解决方法:

这可能有所帮助,这解释了如在Rss Feed应用程序中创建标记

https://professorneurus.wordpress.com/2013/10/23/adding-multiple-clicking-regions-to-an-android-textview/

private void makeTagLinks(final String text, final TextView tv) {
        if (text == null || tv == null) {
            return;
        }
        final SpannableString ss = new SpannableString(text);
        final List items = Arrays.asList(text.split("\\s*,\\s"))
        int start = 0, end;
        for (final String item : items) {
            end = start + item.length();
            if (start < end) {
                ss.setSpan(new MyClickableSpan(item), start, end, 0);
            }
            start += item.length() + 2;//comma and space in the original text ;)
        }
        tv.setMovementMethod(LinkMovementMethod.getInstance());
        tv.setText(ss, TextView.BufferType.SPANNABLE);
    }

标签:android,android-textview
来源: https://codeday.me/bug/20190708/1400643.html