私の問題はこれに関連している可能性があります:
AndroidTouchListViewにフッターを追加する
Commonwareのtouchlistviewのデモプロジェクトhttps://github.com/commonsguy/cwac-touchlist/blob/master/demo/src/com/commonsware/cwac/tlv/demo/TouchListViewDemo.java
簡単なテキストビューがフッターとして追加され、問題なく機能します。代わりに自分で追加すると、アイテムを削除するときに壊れます。最初に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)を返します。
私のカスタムフッターとの違いは誰にわかりますか?