Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class ScrollDisabledListView extends ListView {
private int mPosition;
public ScrollDisabledListView(Context context) {
public ScrollDisabledListView(Context context, AttributeSet attrs) {
super(context, attrs);
public ScrollDisabledListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
public boolean dispatchTouchEvent(MotionEvent ev) {
final int actionMasked = ev.getActionMasked() & MotionEvent.ACTION_MASK;
if (actionMasked == MotionEvent.ACTION_DOWN) {
// Record the position the list the touch landed on
mPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
return super.dispatchTouchEvent(ev);
if (actionMasked == MotionEvent.ACTION_MOVE) {
// Ignore move events
return true;
if (actionMasked == MotionEvent.ACTION_UP) {
// Check if we are still within the same view
if (pointToPosition((int) ev.getX(), (int) ev.getY()) == mPosition) {
} else {
// Clear pressed state, cancel the action
return true;
return super.dispatchTouchEvent(ev);

This comment has been minimized.

Copy link

@cbupp cbupp commented Nov 1, 2015

This looks great! Is there a license to this? Currently, this is protected by your copyright unless you grant usage with a license.

Alternatively, all I need is your permission to use this.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment