Archive for the ‘Android’ Category

Android: InteractiveScrollView

(June 4th, 2010)

This post is a simple follow up to Android: Understanding when ScrollView has reached the bottom where I have created a small plug and play widget which notifies when scroll bottom has been reached through a listener.

It works like this: InteractiveScrollView inherits from ScrollView and overrides onScrollChanged to validate scroll position. If bottom has been reached, onBottomReachedListener triggers.

Usage:

InteractiveScrollView scrollView;    

scrollView = (InteractiveScrollView) findViewById( R.id.scrollView);
scrollView.setOnBottomReachedListener(new InteractiveScrollView.OnBottomReachedListener() {
                @Override
                public void onBottomReached()
                {
                        // bottom reached
                }
});

View the class or download it here.

Android: Understanding when ScrollView has reached the bottom

(May 12th, 2010)

This snippet is pretty mutch as the title says, an example in detecting when ScrollView has reached the bottom. In this sample I extend ScrollView and then overrides the onScrollChanged method (inherited from View).

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
        // Grab the last child placed in the ScrollView, we need it to determinate the bottom position.
        View view = (View) getChildAt(getChildCount()-1);
       
        // Calculate the scrolldiff
        int diff = (view.getBottom()-(getHeight()+getScrollY()));
       
        // if diff is zero, then the bottom has been reached
        if( diff == 0 )
        {
                // notify that we have reached the bottom
                Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
        }

        super.onScrollChanged(l, t, oldl, oldt);
}

Cheers to this thread for helping me getting the calculations right.