Android跨对象
假设我有一个编辑文本:Android跨对象,android,textview,Android,Textview,假设我有一个编辑文本: Editable e = editText.getEditableText(); // length == 2 // ...attach a span start=0, end=2 to e... int index = e.nextSpanTransition(0, 2, Object.class); 据此: 索引应为0,因为它表示 返回大于或等于类类型的标记对象开始或结束位置的第一个偏移量 但是索引是2。这是一个错误还是我遗漏了什么 或者我甚至误解了文档,因为它
Editable e = editText.getEditableText(); // length == 2
// ...attach a span start=0, end=2 to e...
int index = e.nextSpanTransition(0, 2, Object.class);
据此:
索引应为0,因为它表示
返回大于或等于类类型的标记对象开始或结束位置的第一个偏移量
但是索引是2。这是一个错误还是我遗漏了什么
或者我甚至误解了文档,因为它可能意味着“大于标记对象开始的位置,或者等于标记对象结束的位置”文档还说:
或限制
如果没有大于或等于开始
但小于限制
其中limit
是第二个参数(本例中为2)。您的跨度不满足小于限制
,因为它等于它。因此它返回limit
下面是解释它的源代码:
/**
* Return the next offset after <code>start</code> but less than or
* equal to <code>limit</code> where a span of the specified type
* begins or ends.
*/
public int nextSpanTransition(int start, int limit, Class kind) {
int count = mSpanCount;
Object[] spans = mSpans;
int[] starts = mSpanStarts;
int[] ends = mSpanEnds;
int gapstart = mGapStart;
int gaplen = mGapLength;
if (kind == null) {
kind = Object.class;
}
for (int i = 0; i < count; i++) {
int st = starts[i];
int en = ends[i];
if (st > gapstart)
st -= gaplen;
if (en > gapstart)
en -= gaplen;
if (st > start && st < limit && kind.isInstance(spans[i]))
limit = st;
if (en > start && en < limit && kind.isInstance(spans[i]))
limit = en;
}
return limit;
}
查看最后2个if
-句子,在您的例子中,st=0,start=0,en=2,limit=2。第一个if
为假,第二个if
也为假。最后,它返回未更改的limit
参数。您的注释是:附加,所以您的意思可能是setSpan?太好了,我很高兴我提供了帮助,因此此方法在源代码中也有不同的注释:返回start
之后的下一个偏移量,但小于或等于limit
,其中指定类型的跨度开始或结束。