Can't scroll RecyclerView because OnClick in the ViewHolder

711 Views Asked by At

I have an RecyclerView inside a fragment that cannot scroll when I implement OnClick in a ViewHolder.

When I implement the OnClick the list is stock.

I use v.getParent().requestDisallowInterceptTouchEvent(true); to get focus because of the AppBarLayout that is stealling my vertical scrolling.

JAVA:

private void initRecycleView() {
    autoCompleteAdapter = new AutoCompleteSearchAdapter(getActivity(), this);
    autoCompleteList.setLayoutManager(new LinearLayoutManager(getActivity()));
    autoCompleteList.setAdapter(autoCompleteAdapter);
    autoCompleteList.setOnTouchListener(new View.OnTouchListener() {
      @Override public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
      }
    });
  }

XML:

<android.support.design.widget.CoordinatorLayout
    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"
    android:fitsSystemWindows="true"
    >

  <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingTop="10dp"
      android:theme="@style/AppTheme.AppBarOverlay"
      >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="78dp"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        />

    <include layout="@layout/widget_search_bar"/>

  </android.support.design.widget.AppBarLayout>

  <FrameLayout
      android:id="@+id/fragment_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/cardview_dark_background"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      />
</android.support.design.widget.CoordinatorLayout>
1

There are 1 best solutions below

0
On

you can implement a setOnItemClickListener interface for each of the itemViews as I've provided an answer for it here including an explanation of the process. RecyclerView - get Position inside Activity rather than RecyclerViewAdapter