回收者视图检测上下滑动

时间:2018-07-23 12:54:58

标签: android android-recyclerview

如何正确设置RecyclerView来检测向上和向下滑动?

当我放置recycler.setOnTouchListener(this)时 我收到此警告: recyclerview具有setontouchlistener,但没有覆盖perfoclick ,并且没有任何效果。

谢谢。

recyclerView = (RecyclerView)rootview.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(layoutManager);
Adapter adapter=new  
Adapter (List);
recyclerView.setAdapter(adapter);

1 个答案:

答案 0 :(得分:-2)

您应该使用SwipeRefreshLayout并使用setOnRefreshListener示例处理回调。

<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:
   }
});