0

How to disable onScroll() programmatically in Android?

I have overriden method onScroll() in ListActivity. Now, I need to disable this method in certain part of my code. I need it for further logic.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Stas
  • 1,355
  • 6
  • 22
  • 40
  • 1
    Add some boolean variable such as "diableCallback", return back from onScroll() in the first line when it is true and set the value of the variable to true in the parts where the Scroll is not required... This comment is based on a rough idea of your requirement, if you could elaborate and post some part of the code we could guide you in specific. – Sudhaker Jun 05 '12 at 14:34
  • This may be a duplicate of the following question: http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically – Dr. Ferrol Blackmon Jun 05 '12 at 14:35

2 Answers2

1

Without seeng any code: You could set a class level variable in your activity to false when you don't want the list to scroll. You could check this in your onScroll() handler and react accordingly.

I do have to caution you against it though. Will the user understand why it isn't scrolling, or will they be cursing your app because it has locked up?

If you were able to post some code we would be able to help more (possibly suggest a better way).

cstrutton
  • 5,667
  • 3
  • 25
  • 32
1
public class MyList extends ListView{
    private boolean isScrollEnabled = true;

    public void setScroll(boolean scrollEnabled){
        isScrollEnabled = scrollEnabled;
    }


    public void onScrollChanged(int l, int t int oldL, int oldT){
        if !(isScollingEnabled) return;
        super.onScrollChanged(l,t,oldL, oldT);
    }
Rafael T
  • 15,401
  • 15
  • 83
  • 144