Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class ScrollDisabledListView extends ListView {
  2.  
  3. private int mPosition;
  4.  
  5. public ScrollDisabledListView(Context context) {
  6. super(context);
  7. }
  8.  
  9. public ScrollDisabledListView(Context context, AttributeSet attrs) {
  10. super(context, attrs);
  11. }
  12.  
  13. public ScrollDisabledListView(Context context, AttributeSet attrs, int defStyle) {
  14. super(context, attrs, defStyle);
  15. }
  16.  
  17. @Override
  18. public boolean dispatchTouchEvent(MotionEvent ev) {
  19. final int actionMasked = ev.getActionMasked() & MotionEvent.ACTION_MASK;
  20.  
  21. if (actionMasked == MotionEvent.ACTION_DOWN) {
  22. // Record the position the list the touch landed on
  23. mPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
  24. return super.dispatchTouchEvent(ev);
  25. }
  26.  
  27. if (actionMasked == MotionEvent.ACTION_MOVE) {
  28. // Ignore move events
  29. return true;
  30. }
  31.  
  32. if (actionMasked == MotionEvent.ACTION_UP) {
  33. // Check if we are still within the same view
  34. if (pointToPosition((int) ev.getX(), (int) ev.getY()) == mPosition) {
  35. super.dispatchTouchEvent(ev);
  36. } else {
  37. // Clear pressed state, cancel the action
  38. setPressed(false);
  39. invalidate();
  40. return true;
  41. }
  42. }
  43.  
  44. return super.dispatchTouchEvent(ev);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement