zousan
zousan

Reputation: 93

How to make recyclerView_items unclickable, while one of them is clicked and working?

Premise

Each of my RecyclerView_items displays an image, and changes its image_resource when tapped.
One of them is the right answer which has additional function: navigation to another fragment 5-second after changing its image.

Basically, the function of clickListener of RecyclerView_items is

Problem

Then, my problem is that after the right_item is tapped, other items are clickable during delay(5000). I don't want them to change their images during delay(5000).

How to do it?! Thanks in advance.

Upvotes: 1

Views: 719

Answers (3)

Rana Ranvijay Singh
Rana Ranvijay Singh

Reputation: 6165

This is what I understood, you want to lock the entire screen (make all items or buttons unclickable) when you are in delay(5000).
This is what I would do, give a CLICKABLE overlay view on top of recycler view and toggle its visibility.
I used the same for locking the entire screen while making an API call.

view_overlay.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_progress"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:clickable="true"
    android:focusable="true"
    android:elevation="5dp"
    android:visibility="invisible">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent"
        android:indeterminateTint="@android:color/transparent" />
</RelativeLayout>

Obviously you can replace ProgressBar with just View to get a transaprent view.

To include it in your main view, give this at the bottom of your parent layout or below recycler view. Whichever you choose make sure you have the overlay view on top of recycler view.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    ...
    ...
    ...

    <include layout="@layout/view_overlay" />
</RelativeLayout>

Upvotes: 0

Abhishek
Abhishek

Reputation: 329

You can achieve this by adding a flag at time when user click right image then make that variable false. As such after the delay before moving to the next fragment make it true again.

boolean flag = true;

then in your item click method

view.setOnClickListner {
 if (flag) {
   if (rightimageclicked) {
       flag = false;
       delay { 
        flag = true;
        // Move to other fragment  
       }
   } else {
       // change the image for wrong click
   }
 }
} 

Upvotes: 1

Abdur Rahman
Abdur Rahman

Reputation: 1001

The simple trick you can use is make a FrameLayout or View that overlaps on the RecyclerView. Set ists visibility to GONE. Then inside activity or fragment where you can access this FrameLayout or View which is overlapping, add an empty OnClickListener on this view.

*viewId*.setOnClickListener { }

Now set its visibility to VISIBLE when you call delay. When delay finished again set its visibility to GONE

Upvotes: 1

Related Questions