I'm creating a horizontal recycler view that scrolls automatically after a certain time (Say 5 seconds). I used countdowntimer. But, it is not working as expected. the timer is not running properly. Some times it jumps two or more recycler items at a time.
here is my code:
class StoryViewHolder extends RecyclerView.ViewHolder {
{
CountDownTimer timer;
....
}
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int position) {
{
.....
if (holder.timer != null) {
holder.timer.cancel();
}
holder.timer = new CountDownTimer(5000, 1000) {
@Override
public void onTick(long timeLeft) {
}
@Override
public void onFinish() {
StoryFragment.scrollToPosition((position+1));
}
};
holder.timer.start();
}
My question is similar to this question. But the answer they said is not working. Set counter inside RecyclerView
Hope someone will help. Thankyou. }