-1

Is RecyclerView is a ViewGroup?

As in the below code, I am using onInterceptTouchEvent which is used with ViewGroups only and as I am implementing this with recyclerView, is RecyclerView is a ViewGroup? if not then what is the ViewGroup on which I am implementing the onInterceptTouchEvent and what are its views?

I am trying to implement this: link here

Please help me with this.

 static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

        private GestureDetector gestureDetector;
        private ClickListener clickListener;

        public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
            this.clickListener = clickListener;
            gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                    View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                    if (child != null && clickListener != null) {
                        clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                    }
                }
            });
        }

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

            View child = rv.findChildViewUnder(e.getX(), e.getY());
            if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
                clickListener.onClick(child, rv.getChildPosition(child));
            }
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

        }


    }
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
Jatin Verma
  • 363
  • 3
  • 12
  • **Pro tip**: Use [CTRL + Left Mouse] and Select `RecyclerView` in Android Studio and you will know the answer to your question. – Enzokie Sep 09 '17 at 07:20

1 Answers1

0

The RecyclerView class is a ViewGroup subclass that is related to the ListView and GridView classes and that has been made available by Google through the RecyclerView support library for older versions of Android. The RecyclerView class requires the use of the view holder design pattern for efficient item recycling and it supports the use of a LayoutManager, a decorator, and an item animator in order to make this component incredibly flexible at the cost of simplicity.

Ridha Rezzag
  • 3,672
  • 1
  • 34
  • 39
  • view holder design pattern has nothing to do with "efficient item recycling" - it only avoids calling `findViewById` when binding views – pskink Sep 09 '17 at 08:01
  • You can dramatically increase the performance of your application by implementing the ViewHolder design pattern. – Ridha Rezzag Sep 09 '17 at 08:29
  • no, this is not true, in 99% of cases it doesn't really improves the performance, calling findViewById twice or 3 or 4 times doesn't cost much – pskink Sep 09 '17 at 08:32
  • thank you for the info i appreciate it, but for me i learned this from Google and Udacity course developers after i submit a project for a review, i had 5 findview by ids, the teacher suggested for me to use view holder for better performance and shared this link with me to learn more http://spreys.com/view-holder-design-pattern-for-android/ – Ridha Rezzag Sep 09 '17 at 08:49
  • 2
    OK so have you seen the source code of any listview adapters available in the SDK like simple adapter, array adapter, cursor adapter? do they use view holder pattern? no, tell me why if in your opinion it dramatically improves the performance? – pskink Sep 09 '17 at 08:56