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
,其中指定类型的跨度开始或结束。