Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if Android Gridview is scrolled to its top

I want to determine if my Gridview is scrolled to its top.

Right now I'm using getChildAt(0).getTop() to do this. I save the value of getChildAt(0).getTop() on first draw and compare to getChildAt(0).getTop() on subsequent draws .

However, this seems hacky and seems to sometimes give me incorrect results.

Any better ideas?

like image 734
user1435114 Avatar asked Nov 13 '22 02:11

user1435114


1 Answers

Try using the onScrollListener

setOnScrollListener(this);

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    if(firstVisibleItem == 0){
        //do stuff here
    }

}
like image 154
JackMahoney Avatar answered Jan 05 '23 18:01

JackMahoney