为了在RecyclerView
中实现Endless Scroll模式,我想创建一个类
public class EndlessScrollAdapter<VH extends ViewHolder>
extends RecyclerView.Adapter<VH> implements RecyclerView.OnScrollListener {
}
因为
EndlessScrollAdapter
应该同时负责数据和滚动事件的处理,所以这是实现它的最方便的方法。但是,因为在
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
成为类而不是接口(interface)?因为我认为它应该是一个接口(interface)。 最佳答案
我有相同的问题,而且绝对是设计合理的问题,如此错误报告中所述:
https://code.google.com/p/android/issues/detail?id=79283
也可以在这里找到引入它的差异:
https://android.googlesource.com/platform/frameworks/support/+/cef7b49%5E!/
我不确定我个人同意更改,但是可以。
关于android - 为什么RecyclerView.OnScrollListener不是接口(interface)而是抽象类?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28636694/