0

How do I get the amount of pixels which a user has scrolled in a scroll view. I have a scroll view which contains lot of texts. I also have a button at bottom of the screen. What I want is to change text on the button to the amount of scrolling done in the scroll view.

this is code i am using:

import android.app.Activity;


 public class Verbal extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.verbal);

    TextView verintro = (TextView) findViewById(R.id.verbalintro);
    TextView verqstns = (TextView) findViewById(R.id.verqstns);

            ....

 Button answer= (Button) findViewById(R.id.answernumber);
    ScrollView scrollview = (ScrollView) findViewById(R.id.scrollview);
    int scrollposition = scrollview.getScrollY();
    answer.setText(scrollposition);




}

}

the application crashes. i am doing something wrong. all i want is the text on the button to keep changing as the user scrolls up and down.

Abhinav Raja
  • 349
  • 1
  • 5
  • 25
  • You should provide the stacktrace of the Exception. I guess it might crash on setting the button text? Try using `String.valueOf(scrollPosition)` – super-qua Feb 14 '14 at 10:29
  • its working now but its setting text to zero (0). no matter how much i scroll. – Abhinav Raja Feb 14 '14 at 10:34
  • i guess it just shows initial position. its not changing continuously with scrolling. – Abhinav Raja Feb 14 '14 at 10:36
  • Yes it does. To get notified about scrolling you need a listener set on the ScrollView. Unfortunately this cannot be done by simply setting the listener. But http://stackoverflow.com/questions/3948934/synchronise-scrollview-scroll-positions-android has a solution to that issue – super-qua Feb 14 '14 at 10:39
  • I meant of course "Yes it doesn't change - it just shows the initial position" ;) – super-qua Feb 14 '14 at 11:57

0 Answers0