這是上面的回答一些代碼,它在我的情況下工作:
我必須設置它的適配器之前設置一個footerView(這是與分頁列表視圖一個loadingView)我的ListView,然後將其刪除。首先,我在onCreate方法的佈局文件初始化我loadingView:
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
loadingView = layoutInflater.inflate(R.layout.loading_view, null);
然後,我在同樣的方法使用此解決方法:
this.setIsLoading(true);
listView.setAdapter(adapter);
this.setIsLoading(false);
凡
private void setIsLoading(boolean isLoading)
{
this.isLoading = isLoading;
if (isLoading) {
listView.addFooterView(loadingView);
}
else {
listView.removeFooterView(loadingView);
}
}
你知道爲什麼會出現類轉換異常? –
我已經更新了我的回答這個有趣的帖子http://stackoverflow.com/questions/4393775/android-classcastexception-when-adding-a-header-view-to-expandablelistview 我認爲這將回答你的問題。 –
@CodeDroid如果你發現我的答案是正確的,你能否接受它。謝謝 –