Remove header from listView

前端 未结 7 2069
执念已碎
执念已碎 2021-02-01 04:58

I\'m having some problems when trying to remove the header from a listView. At first I use addHeaderView() to add it, but when I change to another layo

相关标签:
7条回答
  • 2021-02-01 05:53

    You can check if header count > 0 then remove the header and add it again.
    its works fine for me.

     View _headerView;
     private void function HandleHeaderView(){
            if(listView.getHeaderViewsCount() > 0)
            {
                listView.removeHeaderView(_headerView);
            }
    
            /* Add list view header */
            _headerView = GetHeaderView();
            listView.addHeaderView(_headerView);
     }
    
    
     private View GetHeaderView()
     {
          View header = getLayoutInflater().inflate(R.layout.header_layout, null);
          // TODO: ...
    
          return header
     }
    
    0 讨论(0)
提交回复
热议问题