Fustigador
Fustigador

Reputation: 6469

RecyclerView Item Getting Clicked When Click on FloatingActionButton in Android

I have a FloatingActionButton over a RecyclerView in my app. The Button is showing ok, but when I click on it, the RecyclerView item below it is getting the click event, instead of the button. If I set the RecyclerView to show over the FloatingActionButton, the Button works as intended.

How to solve this, and make the Button to get the click event?

Thank you.

Upvotes: 0

Views: 1010

Answers (2)

user4696837
user4696837

Reputation:

It can only happen if you don't set onClick Listener on FloatingActionButton. So just set onClick Listener on FloatingActionButton Your problem will be solved....

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Your code to do something if you have
        }
});

If have on action to do just implement a empty listener like above ..

Upvotes: 6

KuLdip PaTel
KuLdip PaTel

Reputation: 1069

Use FrameLayout for screen. you can get all click event,item or floating button.

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">
 <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />
</FrameLayout>

Upvotes: 1

Related Questions