Created
September 9, 2013 17:01
-
-
Save danosipov/6498490 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!