如何在同一textView上设置separeted spans?

时间:2017-03-12 09:52:32

标签: android textview spannablestring

我有一个textView和一个ListView。 当用户单击ListView的元素时,它将被添加到textView中。 我想在电视上分离这些字符串,所以当用户点击TextView上的指定字符串时,我想从电视中删除该元素。 我想我需要SpannableString,但我不能将它们彼此分开。我的意思是我不能对元素执行不同的操作。

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您已经拥有class Mother { } class ChildFoo: Mother { } class ChildBar: Mother { } let motherSubclasses = ... // TODO print(motherSubclasses) // should to return [ChildFoo.self, ChildBar.self] ,则可以SpannableString尝试concat他们:

TextUtils

要创建Spans,您可以使用TextUtils.concat(span1, span2); 方法;

  

setSpan(Object what,int start,int end,int flags)

,例如要创建setSpan,您可以执行此操作:

ClickableSpan

P.S:请记住,你可以为你的Spannable String设置多个span,只要注意一个span的末尾不要与下一个span的开始重叠。