我的問題可能與此相關的一個:touchlistview自定義頁腳阻止列表大小更新
Add footer to Android TouchListView
在Commonware的touchlistview https://github.com/commonsguy/cwac-touchlist/blob/master/demo/src/com/commonsware/cwac/tlv/demo/TouchListViewDemo.java
的演示項目一個簡單的TextView添加爲頁腳該工程確定。當我添加自己的時候,它會在刪除項目時崩潰。最初有4個項目,在移除4個項目後,頁腳停留在5號位置。
這是我如何添加頁腳:
View footerView = ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_cloud, null, false);
這是XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dip"
android:gravity="center_vertical"
>
<ImageView android:id="@+id/add_icon"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_add"
/>
<ImageView android:id="@+id/cloudBG"
android:layout_centerInParent="true"
android:layout_width="230dp"
android:layout_height="60dp"
android:background="@drawable/cl"
/>
</RelativeLayout>
增加調試到onRemove:
Log.d("tlv","count b4 remove "+adapter.getCount()+" aray: "+array.size());
adapter.remove(adapter.getItem(which));
//adapter.notifyDataSetChanged();
Log.d("tlv","count after remove "+adapter.getCount()+" aray: "+array.size());
顯示適配器和數組大小正在更新
我在touchlistview.java中更改了一些代碼,以便在將項目拖動到最低項目下時修復崩潰:
Log.d(「tlv」,「drag from」+ mFirstDragPos +「to」+ mDragPos +「cnt」+ getCount將());
if(mDragPos < getCount()-this.getFooterViewsCount()){// Nino van Hooff: fix out of bounds
mDropListener.drop(mFirstDragPos, mDragPos);
}else{
mDropListener.drop(mFirstDragPos, mDragPos-1);
}
}
unExpandViews(false);
利用getCount函數總是返回相同數量(項目+ 1頁腳的量),項目被刪除
誰知道我的自定義頁腳的區別是什麼,即使後?
你可以發佈一個鏈接到一個完整的示例應用程序,演示問題?您可能會在TouchListView中遇到一些我可能能夠糾正的限制。 – CommonsWare
感謝您的快速回復! [鏈接到完整的eclipse項目](http://hooffzaken.nl/junk/baby_names。zip) –
你的項目很奇怪。就好像你把你的代碼放在'TouchListView'庫項目中,這當然不是設置某種東西的預期方式。我無法通過Eclipse或通過命令行構建它。我會盡我所能在這個問題上做一些嘗試。 – CommonsWare