0

我的问题可能与这个有关:

将页脚添加到 Android TouchListView

在Commonware的touchlistview的demo项目中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","从"+mFirstDragPos+"拖到"+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),即使在项目被删除后也是如此

谁知道我的自定义页脚有什么区别?

4

1 回答 1

0

虽然我无法重现您的问题,但还有其他问题。:-)

即使在基线代码中,如果您从TouchListView应用页脚的 a 中删除一行,您也会得到奇怪的视觉结果。从层次结构视图的角度来看,似乎发生的情况是,对于每个删除的行,页脚都是重复的——删除四行,得到四个页脚。

我不知道为什么会这样。TouchListView忽略了ListAdapter提供其内容的 。也许这才是真正的问题。

目前,我将不得不正式不支持同时拥有页脚和支持删除模式。两者都可以单独使用,但不能组合使用。TouchListView如果您尝试,我将增加运行时异常。

最终,TouchListView真的需要更换。作为我对触摸事件更深入探索的一部分,我可能会在 2012 年替换它。也许其他人会想出他们的。由于大部分代码都是从 AOSP 的音乐应用程序中提取的,因此我进行修复的能力有限。

我很抱歉目前不支持此功能。

于 2011-09-08T13:21:09.207 回答