Open kasim1011 opened 4 years ago
same
I think not only in recyclerview
have solve it ?
hmm i think need. to change to other lib
I've tried debugging this and I found that this part right here is causing it.
On this method of ReadMoreTextView.java
private CharSequence updateCollapsedText() {
int trimEndIndex = text.length();
switch (trimMode) {
case TRIM_MODE_LINES:
trimEndIndex = lineEndIndex - (ELLIPSIZE.length() + trimCollapsedText.length() + 1);
if (trimEndIndex < 0) {
trimEndIndex = trimLength + 1;
}
break;
case TRIM_MODE_LENGTH:
trimEndIndex = trimLength + 1;
break;
}
SpannableStringBuilder s = new SpannableStringBuilder(text, 0, trimEndIndex)
.append(ELLIPSIZE)
.append(trimCollapsedText);
return addClickableSpan(s, trimCollapsedText);
}
When you set the mode to TRIM_MODE_LINES, that case will execute and there are times that the value of trimEndIndex is negative so the if statement below it will execute and when trimLength is greater than the actual text length, this will cause the SpannableStringBuilder to throw and index out of bounds error.
ps. the trimLength have a default value of 240
I found out that one of the reasons for this is old data is still there, because of the recycling mechanism of recyclerview. What I mean is the old text is still there and it was used to calculate other variables within the ReadMoreTextView to initialize it, so by the time that the new text is passed into it will used the precomputed values from the old data. In this case the length of the old text is used to initialize the SpannableStringBuilder which caused the index out of bounds.
I added a setting to recyclerview to disable the recycling mechanism to avoid this issue. Altho it solved it, but it beats the purpose of the recyclerview and it obviously affected the performance. Have to find another way for this. Maybe put a handler inside the ReadMoreTextView to update the data effectively or wait for the recyclerview to finally load the new data first, but don't know how yet. Hope this will help others to figure out this problem once and for all.
i do not have much time to solve the library problem, so i using this lib : https://github.com/devendroid/ReadMoreOption
I have a possible solution. I'll work on this.
ok buddy, if u want to make it easy i think it will better using this layout and toggle hide/show instead of readmore
LinearLayout vertical
LinearLayout horizontal
[TRIM_TEXT] -Read more btn-
LinearLayout horizontal
[FULL_TEXT]
LinearLayout vertical
Is anyone still working on this lib? No pull requests, no commits, is there maybe an updated repo with this issues fixed?
I'm using
ReadMoreTextView
inRecyclerView
. Getting crash due toStringIndexOutOfBoundsException
so many times insideRecyclerView
.