gpt4 book ai didi

Android- getSpans() 总是返回一个长度为 0 的数组

转载 作者:搜寻专家 更新时间:2023-11-01 08:30:41 24 4
gpt4 key购买 nike

这让我发疯:

String message = "Here is some example test with URLs from mattheworiordan.com.
Any of the URLs which are prefixed with www. should become URLs such as www.mattheworiordan.com/path_name.html
And an explicit URL such as http://www.mattheworiordan.com/ should become a URL.
Emails such as matt@google.com should become links to.
Or email mailto links such as mailto:matt@google.com should become links to.
And of course lets not forget querstryings such as http://mattheworiordan.com/?test-param=true_or_false"

SpannableString spannable = new SpannableString(message);
URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
Linkify.addLinks(spannable, Linkify.ALL);
Log.v("data_", "length:" + Integer.toString(spans.length));

URLSpan[] 数组的长度始终为 0。我在这里做错了什么以及如何解析 String 中的所有 url?

编辑:Html.fromHtml(message) 代替 message 参数返回相同的结果。

最佳答案

那是因为你没有任何跨度。在Html.fromHtml的情况下得到 URLSpan , 你必须使用标签 <a href .例如。

String message = "Here is some example test with URLs from mattheworiordan.com.
Any of the URLs which are prefixed with www. should become URLs such as www.mattheworiordan.com/path_name.html
And an explicit URL such as <a href='http://www.mattheworiordan.com/'>http://www.mattheworiordan.com/</a> should become a URL.
Emails such as matt@google.com should become links to.
Or email mailto links such as mailto:matt@google.com should become links to.
And of course lets not forget querstryings such as http://mattheworiordan.com/?test-param=true_or_false"

将产生 1 .如果你不想使用 Html , 那么你必须设置 URLSpan以编程方式

关于Android- getSpans() 总是返回一个长度为 0 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41163325/

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