My problem might be related to this one:
Add footer to Android TouchListView
In the demo project of Commonware's touchlistview https://github.com/commonsguy/cwac-touchlist/blob/master/demo/src/com/commonsware/cwac/tlv/demo/TouchListViewDemo.java
A simple textview is added as footer which works OK. When I add my own instead, it breaks down when removing items. With 4 items initially, The footer stays at position 5 after removing any of the 4 items.
This is how I add the footer:
View footerView = ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_cloud, null, false);
This is the 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>
Adding debug to 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());
Shows that the adapter and array sizes are updated
I changed some code in the touchlistview.java to fix a crash when dragging an item below the lowest item:
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);
The getCount function always returns the same number (amount of items + 1 for footer), even after items are removed
Who know what the difference with my custom footer is?