생각 나는 2 개의 upvotes가 있었기 때문에 나는 나의 대답을 게시해야한다.
iOS 색인을 "실제"로, android의 색인을 "위조"로 사용하는 것이 가장 좋았으며, 이로 인해 모든 것을 iOS 색인으로 변환해야했습니다. graphemeGetIndex는 Java "가짜"색인에서 iOS "실제"색인을 가져오고 grahemeGetLength는 필요한 경우 "실제"길이를 가져옵니다. 당신이
public static int graphemeLength(String s) {
BreakIterator it = BreakIterator.getCharacterInstance();
it.setText(s);
int count = 0;
while (it.next() != BreakIterator.DONE) {
count++;
}
return count;
}
public static int graphemeGetIndex(String wholeString, int mIndex) {
BreakIterator it = BreakIterator.getCharacterInstance();
int realStartIndex = 0;
if (mIndex >= 0) {
String partString = wholeString.substring(0, mIndex);
it.setText(partString);
while (it.next() != BreakIterator.DONE) {
realStartIndex++;
}
}
return realStartIndex;
}
private void recalculateIndices() {
for (final UserMention mention : mMentions) {
final int startFake = mCurrentText.indexOf("@" + mention.getName());
final int startReal = graphemeGetIndex(mCurrentText, startFake);
mention.setRealIndices(new int[]{startReal, startReal + graphemeLength(mention.getName())});
mention.setJavaFakeIndices(new int[]{startFake, startFake + mention.getName().length()});
}
}