0

I have a listView that i need to show a bottom menu when it scrolls up and hide it when scroll down , i have

var mLastFirstVisibleItem = 0

        listView.setOnScrollListener(object : AbsListView.OnScrollListener {
            override fun onScroll(
                view: AbsListView?,
                firstVisibleItem: Int,
                visibleItemCount: Int,
                totalItemCount: Int
            ) {
                // TODO Auto-generated method stub

            }

            override fun onScrollStateChanged(view: AbsListView, scrollState: Int) {
                // TODO Auto-generated method stub 

                val currentFirstVisibleItem = view.firstVisiblePosition

                if (currentFirstVisibleItem > mLastFirstVisibleItem) {

                     this.menuView.visibility = View.INVISIBLE  

                    Log.i("a", "scrolling down...")
                } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {

                      this.menuView.visibility = View.VISIBLE 

                      Log.i("a", "scrolling up...")
                }
                mLastFirstVisibleItem = currentFirstVisibleItem

            }
        })

the problem is the listView has one item with a a textView that has long text , so there is no first and last items it only one item , hence above code always shows the menu as

if (currentFirstVisibleItem > mLastFirstVisibleItem) {

will be

if (0 > 0) {

Which is false , Any way to handle this case ?

peso fao
  • 49
  • 4

0 Answers0