Adapter class cast exception when removing a Footer view?

前端 未结 4 1787
不思量自难忘°
不思量自难忘° 2021-01-02 13:51

I have an exception I never thought I would see. A class cast exception of the adapter when removing a footer view from a ListView (sic).

 java.lang.ClassCa         


        
4条回答
  •  我在风中等你
    2021-01-02 14:17

    Adding to the other answers, if you're adding/removing footers dynamically (such as if they reach the bottom of your list and then you're adding a footer view) the easiest thing is to Override setAdapter in your ListView and add a new View object as the footer there, this will ensure the adapter is wrapped in the HeaderViewListAdapter:

    @Override
    public void setAdapter(ListAdapter adapter) {
        addFooterView(new View(getContext()));
        super.setAdapter(adapter);
    }
    

提交回复
热议问题