Skip to content

Instantly share code, notes, and snippets.

@danosipov
Created September 9, 2013 17:01
Show Gist options
  • Save danosipov/6498490 to your computer and use it in GitHub Desktop.
Save danosipov/6498490 to your computer and use it in GitHub Desktop.
public class ScrollDisabledListView extends ListView {
private int mPosition;
public ScrollDisabledListView(Context context) {
super(context);
}
public ScrollDisabledListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollDisabledListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
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) {
super.dispatchTouchEvent(ev);
} else {
// Clear pressed state, cancel the action
setPressed(false);
invalidate();
return true;
}
}
return super.dispatchTouchEvent(ev);
}
}
@cbupp
Copy link

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.

Thanks!

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