Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2011
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import android.content.Context;
  2. import android.view.MotionEvent;
  3. import android.view.View;
  4. import android.widget.ScrollView;
  5.  
  6. class LockableScrollView extends ScrollView {
  7.  
  8.  
  9.     public LockableScrollView(Context context) {
  10.         super(context);
  11.         // TODO Auto-generated constructor stub
  12.     }
  13.  
  14.     // true if we can scroll (not locked)
  15.     // false if we cannot scroll (locked)
  16.     private boolean mScrollable = true;
  17.  
  18.     public void setIsScrollable(boolean scrollable) {
  19.         mScrollable = scrollable;
  20.     }
  21.     public boolean getIsScrollable(){
  22.         return mScrollable;
  23.     }
  24.  
  25.     @Override
  26.     public boolean onTouch(View v, MotionEvent ev) {
  27.         switch (ev.getAction()) {
  28.             case MotionEvent.ACTION_DOWN:
  29.                 // if we can scroll pass the event to the superclass
  30.                 if (mScrollable) super.onTouch(v, ev);
  31.                 // only continue to handle the touch event if scrolling enabled
  32.                 return mScrollable;
  33.             default:
  34.                 return super.onTouchEvent(v, ev);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement