Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 23rd, 2011  |  syntax: Java  |  size: 1.06 KB  |  views: 337  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }