要在RecyclerView
我想创建一个类似的类中实现 Endless Scroll 模式
public class EndlessScrollAdapter<VH extends ViewHolder>
extends RecyclerView.Adapter<VH> implements RecyclerView.OnScrollListener {
}
因为EndlessScrollAdapter
应该同时负责数据和滚动事件的处理,这是最方便的实现方式。
但是,因为 in recyclerview-v7-21.0.3
,OnScrollListener
这样声明
/**
* An OnScrollListener can be set on a RecyclerView to receive messages
* when a scrolling event has occurred on that RecyclerView.
*
* @see RecyclerView#setOnScrollListener(OnScrollListener)
*/
abstract static public class OnScrollListener {
/**
* Callback method to be invoked when RecyclerView's scroll state changes.
*
* @param recyclerView The RecyclerView whose scroll state has changed.
* @param newState The updated scroll state. One of {@link #SCROLL_STATE_IDLE},
* {@link #SCROLL_STATE_DRAGGING} or {@link #SCROLL_STATE_SETTLING}.
*/
public void onScrollStateChanged(RecyclerView recyclerView, int newState){}
/**
* Callback method to be invoked when the RecyclerView has been scrolled. This will be
* called after the scroll has completed.
*
* @param recyclerView The RecyclerView which scrolled.
* @param dx The amount of horizontal scroll.
* @param dy The amount of vertical scroll.
*/
public void onScrolled(RecyclerView recyclerView, int dx, int dy){}
}
我无法EndlessScrollAdapter
实现OnScrollListener
。
所以正如标题所说,有什么好的理由OnScrollListener
成为一个类而不是一个接口?因为我认为它应该是一个接口。