0

リストに SwipeListView ライブラリを使用しています。リスト アダプターは ViewHolder パターンを使用しており、すべて正常に動作しています。左にスワイプを設定すると、リスト アイテム ビューの下に背面ビューが表示されます。この背面図には、「削除」というテキスト ビューがあります。クリック後、削除操作中です。アダプタのデータを更新中です。行が削除されます..しかし、削除された行に近い位置にある行に「スワイプ状態」が設定されています。「スワイプ状態」がconvertviewに記憶されているために発生すると思います。convertview が null かどうかを確認してコメントアウトすると、問題はなくなりましたが、リストのスクロールのパフォーマンスは許容できません。削除アクション後に convertview をクリアする方法はありますか? または、他の回避策はありますか?

私のビューホルダー:

public static <T extends View> T get(View view, int id) {
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
    if (viewHolder == null) {
    viewHolder = new SparseArray<View>();
    view.setTag(viewHolder);
    }
View childView = viewHolder.get(id);
if (childView == null) {
    childView = view.findViewById(id);
    viewHolder.put(id, childView);
    }
return (T) childView;
}

私のアダプターの getView():

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        convertView = LayoutInflater.from(context)
                .inflate(R.layout.level_item, parent, false);
    }

    ...
    ...
    del = ViewHolderNew.get(convertView, R.id.del);

    del.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Level level = list.get(position);
            long id = level.getId();
            Level leveltoDelete = Level.load(Level.class, id);

            new Delete().from(Recipient.class).where("level = ?", id).execute();
            leveltoDelete.delete();

            remove(level);
            notifyDataSetInvalidated();

        }
    }); 

そして私のxmlファイル:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:background="@color/white_background"
>
//item back layout
<LinearLayout
    android:id="@+id/item_back"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<TextView
    android:id="@+id/del"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:gravity="center_vertical|right"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:background="@color/delete_background"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:paddingRight="30dp"
    android:textColor="@color/white_background"
    android:text="Delete"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

//item front layout
<RelativeLayout
android:id="@+id/item_front"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
4

1 に答える 1