question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BottomSheetDialogFragment] RecyclerView items inside BottomSheetDialogFragment need double touch after fast scrolling

See original GitHub issue

I have a RecyclerView inside BottomSheetDialogFragment. The RecyclerView items touch working normally when it’s scrolling slowly.

But when the RecyclerView is scrolled fast and after the list stops (without touching), than touching on any item doesn’t work on fast touch. It needs double touching.

See in the below example gif, when touching on Andhra Pradesh it’s working fine. After slow scrolling, touching on Haryana also works fine. Then doing a fast scroll and touching on Punjab doesn’t work on the first touch. Touching again it works.

RV GIF

Following is the code: OperatorListDialogFragment.java

package com.*;

import *;

public class OperatorListDialogFragment extends BottomSheetDialogFragment{

    private static final String ARG_NAME = "item_name";
    private static final String ARG_LOGO = "item_logo";
    private Listener mListener;
    private String header;
    private Context mContext;

    public static OperatorListDialogFragment newInstance(String[] name, int[] logo, String header) {
        final OperatorListDialogFragment fragment = new OperatorListDialogFragment();
        final Bundle args = new Bundle();
        args.putStringArray(ARG_NAME, name);
        args.putIntArray(ARG_LOGO, logo);
        args.putString("header", header);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

        TextView headerTV = view.findViewById(R.id.title);
        headerTV.setText(getArguments().getString("header"));

        final RecyclerView recyclerView = view.findViewById(R.id.list);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(new OperatorAdapter(getArguments().getStringArray(ARG_NAME), getArguments().getIntArray(ARG_LOGO)));

        view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        mContext = context;

        final Fragment parent = getParentFragment();
        if (parent != null) {
            mListener = (Listener) parent;
        } else {
            mListener = (Listener) context;
        }
    }

    @Override
    public void onDetach() {
        mListener = null;
        super.onDetach();
    }

    public interface Listener {
        void onFilterSelected(String selected, String selectedQuery);
    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        final TextView text;
        ImageView logo;

        ViewHolder(LayoutInflater inflater, ViewGroup parent) {
            // TODO: Customize the item layout
            super(inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog_item, parent, false));
            text = itemView.findViewById(R.id.tv_operator_name);
            logo = itemView.findViewById(R.id.iv_recharge_provider_icon);
        }
    }

    private class OperatorAdapter extends RecyclerView.Adapter<ViewHolder> {

        private String[] mNames;
        private int[] mLogos;

        OperatorAdapter(String[] name, int[] logo) {
            mNames = name;
            mLogos = logo;
        }

        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
        }

        @Override
        public void onBindViewHolder(final ViewHolder holder, final int position) {

            holder.text.setText(mNames[position]);

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("clicked", "" + position);
                }
            });
        }

        @Override
        public int getItemCount() {
            return mNames.length;
        }
    }
}

dialog.xml

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

    <ImageView
        android:focusable="true"
        android:clickable="true"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:contentDescription="Close"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/dismiss"
        android:padding="14dp"
        android:src="@drawable/ic_close_black_24dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/title"
        app:layout_constraintTop_toTopOf="@id/dismiss"
        app:layout_constraintBottom_toBottomOf="@id/dismiss"
        app:layout_constraintLeft_toRightOf="@id/dismiss"
        android:padding="14dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        tools:text="Select operator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <View
        app:layout_constraintTop_toBottomOf="@id/dismiss"
        android:background="#969696"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"/>

    <androidx.recyclerview.widget.RecyclerView
        app:layout_constraintTop_toBottomOf="@id/dismiss"
        app:layout_constraintBottom_toBottomOf="parent"
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        app:layout_constrainedHeight="true"
        android:paddingTop="@dimen/list_item_spacing_half"
        android:paddingBottom="@dimen/list_item_spacing_half"
        tools:context=".fragments.OperatorListDialogFragment"
        tools:listitem="@layout/fragment_operator_list_dialog_list_dialog_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

recycler_item.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:id="@+id/ll_operator_list_wrapper"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:visibility="gone"
        android:layout_marginLeft="16dp"
        android:id="@+id/iv_recharge_provider_icon"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_marginVertical="16dp"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_bsnl_logo"
        tools:visibility="visible"/>

    <TextView
        android:padding="16dp"
        android:textColor="#212121"
        android:textSize="14sp"
        android:ellipsize="end"
        android:id="@+id/tv_operator_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="BSNL"
        android:layout_toRightOf="@+id/iv_recharge_provider_icon"
        android:layout_centerInParent="true"/>

    <View
        android:layout_below="@id/iv_recharge_provider_icon"
        android:id="@+id/divider0"
        android:background="#eeeeee"
        android:visibility="visible"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_marginLeft="16dp"
        android:layout_toRightOf="@+id/iv_recharge_provider_icon"
        />

</RelativeLayout>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

4reactions
VishnuKantAgarwalcommented, Sep 5, 2020

add android:nestedScrollingEnabled="false" in RecyclerView

0reactions
bhavin-qfonappcommented, May 9, 2022

I have RecyclerView inside ConstraintLayout and when I scrolldown view from top not fully came down

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView items inside BottomSheetDialogFragment need ...
The RecyclerView items touch working normally when it's scrolling slowly. But when the RecyclerView is scrolled fast and after the list stops ( ......
Read more >
I've encountered the issue of RecyclerView not be able to ...
I've encountered the issue of RecyclerView not be able to scroll inside BottomSheet unless somehow it gets the touch focus, this can be...
Read more >
Handling Scrolls with CoordinatorLayout - CodePath Cliffnotes
Scroll events in the RecyclerView trigger changes inside views declared within AppBarLayout by using the app:layout_scrollFlags attribute:
Read more >
Slow rendering - Android Developers
If you see a lot of inner items inflating when you first scroll down the page, you may want to check that you're...
Read more >
Android Bottom Sheet Behavior and Animated Button on Top ...
BottomSheetDialogFragment is a thin layer on top of the regular support library Fragment that renders your fragment as a modal bottom sheet.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found