ClassCastException with ListView when executing notifyDataSetChanged

前端 未结 6 1252
醉酒成梦
醉酒成梦 2020-12-08 19:11

I have added a view to the header of listVivew,

    View TopSearch =  (View) View.inflate(this, R.layout.search, null);
    lv.addHeaderView(TopSearch, null         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 19:27

    API 18 and lower is confused about what it is wrapping. To help it, set your header and/or footer PRIOR to assigning the adapter. That way the correct wrapping takes place under the covers. Then remove the header/footer immediately after (if that is what you want).

    myList.addFooterView(myFooterView);
    myList.setAdapter(adapter);
    myList.removeFooterView(myFooterView);
    

提交回复
热议问题