-4

Please, I want to show popup for user if he scrolled scrollview which at bottom, how can i check scrollview at bottom or not ? Is there methods to check from that ?

Ahmed Mohammed
  • 337
  • 2
  • 15
  • This link may help you try this http://stackoverflow.com/questions/10316743/detect-end-of-scrollview – Karthikeyan Apr 23 '15 at 10:05
  • You can refer following post: http://stackoverflow.com/questions/4953692/android-detecting-when-scrollview-hits-bottom – BSavaliya Apr 23 '15 at 10:09

2 Answers2

1

In your case: ScrollView, please check http://developer.android.com/reference/android/widget/ScrollView.html#onOverScrolled%28int,%20int,%20boolean,%20boolean%29 - Klotor

Implement an OnScrollListener, set your ListView's onScrollListener and then you should be able to handle things correctly.

For example:

private int preLast;

// Initialization stuff. yourListView.setOnScrollListener(this);

// ... ... ...

@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
                 final int visibleItemCount, final int totalItemCount) {
    switch(lw.getId()) {
        case android.R.id.list:     

            // Make your calculation stuff here. You have all your
            // needed info from the parameters of this function.

            // Sample calculation to determine if the last 
            // item is fully visible.
           final int lastItem = firstVisibleItem + visibleItemCount;
           if(lastItem == totalItemCount) {
              if (preLast != lastItem){ //to avoid multiple calls for last item
                Log.d("Last", "Last");
                preLast = lastItem;
                //show your popup code
              }
           }
    }
}
Thanh Le
  • 754
  • 3
  • 13
  • or go for `onOverScrolled()` - http://developer.android.com/reference/android/widget/ScrollView.html#onOverScrolled%28int,%20int,%20boolean,%20boolean%29 – Klotor Apr 23 '15 at 10:00
0

Try something like this:

@Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    View view = (View) getChildAt(getChildCount()-1);
    int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
    if( diff == 0 ){  // if diff is zero, then the bottom has been reached
        Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
    }
    super.onScrollChanged(l, t, oldl, oldt);
}

Thanks to Harry Joy link

Community
  • 1
  • 1
Karol Żygłowicz
  • 2,202
  • 2
  • 19
  • 30