-2

How can i set up my RecyclerView properly to detect swipe Up and Down?

When i place recycler.setOnTouchListener(this) I get this warning: recyclerview has setontouchlistener but does not override perfoclick and nothing works.

Thank you.

recyclerView = (RecyclerView)rootview.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(layoutManager);
Adapter adapter=new  
Adapter (List);
recyclerView.setAdapter(adapter);
plase
  • 361
  • 1
  • 3
  • 9
Nick
  • 2,818
  • 5
  • 42
  • 60
  • You can use the SwipeLayout for upside pull and And for the downside you can use the addOnScrollListener listener of the recyclview – Ravindra Kushwaha Jul 23 '18 at 12:56
  • maybe it help : https://stackoverflow.com/questions/29024058/recyclerview-scrolled-up-down-listener – Farshid roohi Jul 23 '18 at 12:58
  • Please read the question carefully. I want to detect Swipe not just scrolling – Nick Jul 23 '18 at 13:00
  • @Nick you will have to use onTouchListener(). And this warning has nothing to do with no clicking or anything. You should put a debugger and fine out the exact issue. – Umair Jul 23 '18 at 13:04
  • @Umair There is nothing wrong with the code. Recycler works fine ntil i put the touchListener. You should try it. – Nick Jul 23 '18 at 13:05
  • check this link maybe help you https://stackoverflow.com/a/48520345/9312502 – denizs Jul 23 '18 at 13:07
  • @Nick the problem is in your code. I have tried it and onTouchListener() is working fine. And about the warning you should read this. https://stackoverflow.com/questions/47107105/android-button-has-setontouchlistener-called-on-it-but-does-not-override-perform?rq=1 . As you cann see it has nothing to do with your problem – Umair Jul 23 '18 at 13:14
  • @Umair Then, If you are kind enough could you please share the code with us? – Nick Jul 23 '18 at 13:19
  • take a look at this code snippet https://stackoverflow.com/questions/6645537/how-to-detect-the-swipe-left-or-right-in-android . If that doesn't help then tell me. – Umair Jul 23 '18 at 13:20
  • @Umair The link you provided. implements the events to the whole Activity and not to the specific view. If you attach on recycler specifically you will get the warning. – Nick Jul 23 '18 at 13:30

1 Answers1

-2

You should be using SwipeRefreshLayout and handle the callback with setOnRefreshListener example.

<android.support.v4.widget.SwipeRefreshLayout
   android:id="@+id/swRefresh"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <android.support.v7.widget.RecyclerView
   android:id="@+id/recyclerView"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>


SwipeRefreshLayout mSwRefresh=findViewById(R.id.SwRefresh);;
mSwRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
   @Override
   public void onRefresh() {
    //TODO:
   }
});
nyulan
  • 311
  • 3
  • 12