ClassCastException with ListView when executing notifyDataSetChanged

前端 未结 6 1240
醉酒成梦
醉酒成梦 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:47

    As written in http://stanllysong.blogspot.ru/2013/08/javalangclasscastexception.html it should be done so:

    HeaderViewListAdapter hlva = (HeaderViewListAdapter)l.getAdapter();
    YourListAdapter postAdapter = (YourListAdapter) hlva.getWrappedAdapter();
    postAdapter.notifyDataSetChanged();
    

提交回复
热议问题