Android錯誤記錄

Android錯誤記錄

  • ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.AbsListViewLayoutParams cannot be cast to android.widget.AbsListViewLayoutParams
    問題描述:自定義下拉刷新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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章