0

In BindViewHolder method I have used -

new CountDownTimer(10000, 1000) {

        public void onTick(long millisUntilFinished) {
            holder.timer_tv.setText(String.format("00:%02d", millisUntilFinished / 1000));
        }

        public void onFinish() {
            holder.switchScreen();

        }
    }.start();

and in holder I have used switchScreen method

    private void switchScreen() {
        System.out.println("SWITCH ADAPTER POSITION: " + getAdapterPosition());
        if (getAdapterPosition() < list.size() - 1) {
            recyclerView.scrollToPosition(getAdapterPosition() + 1);
            System.out.println("SWITCH1: " + getAdapterPosition());
        } else {
            System.out.println("SWITCH2: " + getAdapterPosition());
            context.startActivity(new Intent(context, WordTestResultActivity.class).putExtra("correct_words", correct_words).putExtra("total_words", total_words));
            ((WordTestActivity) context).finish();
        }
    }

Example : If I have 4 items in RecyclerView then switchScreen() skipping some items but I want each one to show one by one.

If I use a button in holder, implement its click listener and on click event I use this switch screen method it works good by showing each item one by one.

Chirag Jain
  • 628
  • 11
  • 24

1 Answers1

0

Atually problem is in switchScreen() method. For button click event it is working good but for this CountDownTimer I have to change switchScreen() method as below by removing +1 from -

recyclerView.scrollToPosition(getAdapterPosition());

and removed -1 from -

if (getAdapterPosition() < list.size()) {

But it creates some problems too as now timer is not being updated on textview after 1st item, it sticks to 00:01 for rest of next items also it doesn't go in else part of switchScreen method() after last item display.

Chirag Jain
  • 628
  • 11
  • 24