假设您有这个界面:
public interface OnItemTouchListener {
boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e);
void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e);
void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept);
}
您决定自己实现它:
public class MyOwnOnItemTouchListener implements OnItemTouchListener {
@Override
boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
boolean result = doSomething(e);
return result;
}
@Override
void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
doSomethingElse(rv, e);
doSomethingMore(rv);
}
@Override
void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
if (disallowIntercept) {
doADifferentThing();
}
}
}
一切都很好...
...直到,从现在起六个月后,被修改以引入一种新的方法:OnItemTouchListener
public interface OnItemTouchListener {
boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e);
void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e);
void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept);
// New method
void onMultiTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e);
}
突然之间,您的应用程序将不再编译