There are 4 items of RecyclerView click implemented on LinerLayout , if the user clicks on one of the items, it is necessary that within 3 seconds the clicks of all items are disabled, how to be?

UPD

Click an item from the RecyclerView adapter

 holder.linearClick.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { // code } }); 

It is to this click that I need to set the shutdown of items for 3 seconds. I made a simple .setEnabled(false) and the clicked click is inactive, but the other 3 are active. I need to disable the entire array in the recycle adapter

  • Do you need to make them inactive / non-clickable, or just so that the code in onClick is not executed? - woesss
  • After a click, I set the background color, 4 items, these are answer options, and accordingly, after a clicked answer, I need other answers to be inactive. And after 2 seconds, the question is changed by scrolling through the ViewPager in which it is all located. - McDaggen

2 answers 2

Create a field to save the time of pressing and, when clicked, compare with the current time:

 private long mLastClickedTime; ----------------------------- public void onClick(View v) { long current = System.currentTimeMillis(); if ((current - mLastClickedTime) < 3000L) return; mLastClickedTime = current; // some code } 
  • Something I did not understand, I'm sorry. Now I will update the question - McDaggen

You can do with CountDownTimer

  ViewHolder.disableClick() new CountDownTimer(3000, 3000) { public void onTick(long millisUntilFinished) { } public void onFinish() { ViewHolder.enableClick() } }.start(); 
  • Logic in my recycler adapter - McDaggen
  • Well, what can be done, after clicking on item, set the lock flag and request an update of the entire list of notifyDataSetChanged () and in onCreateViewHolder (), perform a click lock on views with a timer. - Ruslan Yagupov