.
, — RecyclerView. , RecyclerViewEx, API- :
public class RecyclerViewEx extends RecyclerView {
interface OnScrollStateChangedListener {
void onScrollStateChanged(int state);
}
final private ArrayList<OnScrollStateChangedListener> listeners=new ArrayList<>();
public RecyclerViewEx(Context context) {
super(context);
}
public RecyclerViewEx(Context context, @Nullable
AttributeSet attrs) {
super(context, attrs);
}
public RecyclerViewEx(Context context, @Nullable AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public void addOnScrollStateChangedListener(OnScrollStateChangedListener listener) {
listeners.add(listener);
}
public void removeOnScrollStateChangedListener(OnScrollStateChangedListener listener) {
listeners.remove(listener);
}
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
for (OnScrollStateChangedListener listener : listeners) {
listener.onScrollStateChanged(state);
}
}
}
scrollToPosition() , . , .
rve.addOnScrollStateChangedListener(
scrollState -> {
if (scrollState==RecyclerView.SCROLL_STATE_IDLE) {
// do something cool, now that the user swipe is complete
}
});
, - , .