I have added a view to the header of listVivew,
View TopSearch = (View) View.inflate(this, R.layout.search, null);
lv.addHeaderView(TopSearch, null
The reason for class cast exception is that the listview did't wrapped to headerlistview. So we can't add footers or header to listview directly. So before setting adapter to listview, add dummy view as header or footer view. Then set adapter to listview. This makes listview to instance of headerviewslist. Then you can add and remove footers easily from listview as normal.
listview.addFooterView(new View(mContext));listview.setAdapter(yourAdapter):
After setting adapter, you can add or remove footer listview.addFooterView(yourFooter); or listview.removeFooterView(yourFooter);