Android錯誤記錄
- ClassCastException: android.widget.LinearLayoutLayoutParams
問題描述:自定義下拉刷新listview(RefreshList extends ListView)時,需要在這個RefreshList 中添加頭佈局:
addHeaderView(下拉刷新View)。運行時出現了這個錯誤。
原因:根據錯誤提示,是佈局參數類型轉化出現了問題,我需要加入到listview頭部的佈局是LinearLayout,所以可以判斷是listView的佈局參數類型是AbsListView.LayoutParams
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
refreshView.setLayoutParams(lp);
//將下拉刷新添加到頭佈局中
addHeaderView(refreshView);
這裏需要感謝這篇博客:https://blog.csdn.net/iblade/article/details/50957767