How to find out if ListView has scrolled to top Most position?

后端 未结 10 940
情歌与酒
情歌与酒 2020-12-29 03:09

I have a ListView, first its scrolled down, now when we scroll up,it reach top most point. I want to detect that .Is there any way?I am developing application with api level

10条回答
  •  独厮守ぢ
    2020-12-29 03:57

    If you can extends ListView directly, then you can use the protected method called "computeVerticalScrollOffset()" inside the override method "onScrollChanged()".

    With that protected method return 0, means that your ListView is now reached at top.

    Code Snippet

            listView = new ListView(this){
            @Override
            protected void onScrollChanged(int l, int t, int oldl, int oldt) {
                super.onScrollChanged(l, t, oldl, oldt);
    
                if( computeVerticalScrollOffset() == 0 ){
                    // Reach top
                }
            }
    

提交回复
热议问题