It seems like a frequently asked question but it is not. So I want to execute a method on clicking recyclerview. I have nothing to do with recyclerview items. I want the app to recognize a screen tap to implement a method.
Here's the code:
xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:id="@+id/rl">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:paddingTop="8dp"
android:visibility="visible"
/>
</RelativeLayout>
Java
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mRecyclerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"sent",Toast.LENGTH_SHORT).show();
}
});
Now on tapping on recyclerview area, the toast doesn't show up.