I want to make letters in my Views
in ListView
gradually disappear. I created a method like this inside my View
class to change the alpha to 0 on every letter with delay using the Handler
:
public void clearLetter(final int textPosition, final BaseFragmentAdapter adapter) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
...
text.setSpan(new ForegroundColorSpan(Color.alpha(0)), 0, textPosition, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
adapter.notifyDataSetChanged();
if (hasMoreLetters) {
clearLetter(textPosition + 1, adapter);
}
}
}, 300);
}
Everything works fine until I start scrolling too fast: I get IndexOutOfBoundsException
. I understand that the views get recycled and the text changes so the job in an already launched Handler
is trying to get the previous text, thus giving the exception.
But I'm not sure how to overcome this problem. I want text in the views to disappear anyway, whether the views, that hold the text, are inside the visible zone or not. I tried not to recycle the views and all worked fine except for performance, so it's not an option.
Thank you in advance for any tips that might help.