Listview - Footer at the bottom of screen

前端 未结 4 554

I have a ListView with a footer added with listview.addFooterView(footerView);

All works as expected excepted in one case: when my listview\'s items doe

4条回答
  •  情话喂你
    2020-12-17 16:45

    In addition to @codeMagic response, you could add a listener to check when your adapter gets updated and then update the footer

    registerDataSetObserver(new DataSetObserver() {
                @Override
                public void onChanged() {
                    super.onChanged();
                    updateSmartFooter();
                }
            });
    

    where updateSmartFooter is the function he described

     private void updateSmartFooter {
         listView.post(new Runnable()
         {       
             public void run()
            {
                int numItemsVisible = listView.getLastVisiblePosition() - 
                listView.getFirstVisiblePosition();
                if (itemsAdapter.getCount() - 1 > numItemsVisible)
                {   
                     // set your footer on the ListView
                }
                else
                {
                     footerView.setVisibility(View.VISIBLE);
                }
             }
          }
    }
    

提交回复
热议问题