androidonscrolllisteneronscrollchanged

how to check scroll bottom and top


bellow source code is not perfect code.

work to one side, work to only bottom side.

how to edit?

please give me edit example.

list.setOnScrollListener(new OnScrollListener() {

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

        }

        int mPosition=0;
        int mOffset=0;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
             // TODO Auto-generated method stub
                int position = list.getFirstVisiblePosition();
                View v = list.getChildAt(0);
                int offset = (v == null) ? 0 : v.getTop();

                 if (mPosition < position || (mPosition == position && mOffset < offset)){
                      // Scrolled up 

                 } else {
                      // Scrolled down

                }
        }
     }); 

Solution

  • Have you try scrollView.fullScroll(ScrollView.FOCUS_UP); and scrollView.fullScroll(ScrollView.FOCUS_DOWN);