Answer the question
In order to leave comments, you need to log in
Event when ScrollView is scrolled to the end?
Good evening.
I am developing an application for android and faced the need to reload content when the scroll reaches the end of the page.
How can this be implemented? Maybe there is some event on the ScrollView?
Searched the Internet, found nothing useful. Preferably with a detailed example.
Tried this method, doesn't work:
@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);
}
Answer the question
In order to leave comments, you need to log in
In response to comments on the question:
Wolfak : The "Override" annotation says that this method is overridden. It can be redefined ONLY IN THAT class where it has already been described earlier.
Such a method is in the ScrollView class, respectively, it is in it that this method must be overridden and an object created.
This method is called by the scrollview whenever the position of the scrollview changes. Accordingly, you need to make a change in the logic of work (add your own actions).
There are 2 common ways (there are others).
First:
ScrollView scroll = new ScrollView(context){ //context - то что должно быть внутри скрола
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
//тут, надо вставить то, что хочешь ( то что описано в твоем методе
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question