Hide custom search bar if all items in adapter are showing

后端 未结 4 742
Happy的楠姐
Happy的楠姐 2021-01-29 12:24

The problem I have is that listView.getLastVisiblePosition always returns -1 so I can\'t hide the searchView. I check this right after setting the

4条回答
  •  灰色年华
    2021-01-29 12:34

    Thanks to zapl's answer I was able to get what I needed. I thought I would post the full code in case it helps anyone

    listView.post(new Runnable()
    {       
        public void run()
        {
            int numItemsVisible = listView.getLastVisiblePosition() - 
                    listView.getFirstVisiblePosition();
            if (itemsAdapter.getCount() - 1 > numItemsVisible)
            {   searchField.setVisibility(View.VISIBLE);    }                                   
            else
            {   
                searchField.setVisibility(View.GONE);   
                setFilters("searchtext", "");
            }               
        }
    });
    

提交回复
热议问题