2017-01-30 18 views

ответ

0
class RecyclerTouchListener implements RecyclerView.OnItemTouchListener { 

    private GestureDetector gestureDetector; 
    private ClickListener clickListener; 

    public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) { 
     Log.d("TAG", "Constructer invoked"); 
     this.clickListener = clickListener; 
     gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 
      @Override 
      public boolean onSingleTapUp(MotionEvent e) { 
       Log.d("TAG", "onSingleTapUp" + 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.getChildAdapterPosition(child)); 
       } 
       Log.d("TAG", "onLongPress" + e); 
      } 
     }); 
    } 

    @Override 
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 
     Log.d("TAG", "onInterceptTouchEvent" + gestureDetector.onTouchEvent(e) + " " + e); 

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

    @Override 
    public void onTouchEvent(RecyclerView rv, MotionEvent e) { 
     Log.d("TAG", "onTouchEvent" + e); 
    } 

    @Override 
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 

    } 
} 

Конечно эта ссылка поможет вам-https://www.youtube.com/watch?v=RS7HIaRalhw

+0

Спасибо! Эта работа прекрасна. – user7487983

 Смежные вопросы

  • Нет связанных вопросов^_^