gpt4 book ai didi

android - TextView android中字符串的每个单词上的多个onclicklistener

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:01 24 4
gpt4 key购买 nike

我想在 TextView 中添加多个可点击的链接!获取每个点击文本的响应。

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 - TextView android中字符串的每个单词上的多个onclicklistener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30349749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com