【发布时间】:2015-05-08 12:18:13
【问题描述】:
所以我有一个 android 项目,我可以很好地使用排序功能。我一直在用DevBytesListViewDraggingAnimationhttps://www.youtube.com/watch?v=_BZIvjMgH-Q
我已经让它在我的应用程序和布局中工作,但仍然存在一个大问题,我无法让它与我的自定义 ListView 项目一起工作。 DevBytes 代码中的库存项目是一个普通的 TextView,如下所示:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:textSize="@dimen/list_text_size"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:minHeight="@dimen/list_item_height"
android:textColor="#000000"
/>
我的自定义 ListView 项目由一个 RelativeLayout 和四个 TextViews 组成。因此:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="adress"
android:id="@+id/item_adressView"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/item_driveTypeView"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="postnr, ort"
android:id="@+id/item_zipcodePlaceView"
android:textSize="15dp"
android:layout_below="@+id/item_adressView"
android:layout_toEndOf="@+id/item_driveTypeView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="företag"
android:id="@+id/item_companyView"
android:textSize="15dp"
android:layout_below="@+id/item_zipcodePlaceView"
android:layout_toEndOf="@+id/item_driveTypeView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="P1"
android:id="@+id/item_driveTypeView"
android:textSize="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
诚然,我不太了解数据结构。我所做的每一次更改它以接受我的项目的尝试都会使程序崩溃。我担心在某些尝试中我更改的代码部分比需要的要多。有人可以帮我指出我必须更改代码的哪些部分才能让ListView 接受我的自定义项目吗?
发布所有java代码会使我的帖子超出字符限制。
代码可以在这里找到: http://developer.android.com/shareables/devbytes/ListViewDraggingAnimation.zip
【问题讨论】:
-
Every attempt I've made at changing it to accept my items has crashed the program- 发布您从 Logcat 获得的异常 -
我没有保留所有的例外情况,我猜是因为我从来没有接近过我做对了的想法。在代码中引用相对布局中的文本视图而不是纯文本视图会生成以下内容(尽管我怀疑这会有很大帮助): 原因:java.lang.ClassCastException:android.widget.RelativeLayout 无法转换为 android.widget。 TextView [LegacyBackupAccountManager] 无法获取旧版传输上下文。 android.content.pm.PackageManager$NameNotFoundException:找不到应用程序包 com.google.android.backup
-
自从我实施了这个项目,我就非常了解它。目前,您可以做的最简单的事情是在您的自定义布局中只有一个 TextView UI。原因是 StableArrayAdapter 只有一种方法只能接受 textview UI。查看代码 StableArrayAdapter(Context context, int textViewResourceId...)。这就是原因。也许稍后我会发布答案。
-
非常感谢原始 Android 的深入回答。您的意思是它只接受列表视图上的每个项目一个字符串?例如,我希望能够拥有不同大小文本的项目。
-
我很惊讶您收到错误“java.lang.ClassCastException”。我知道你改变了布局。您是否更改了 ListViewDraggingAnimation 应用程序中的任何 Java 代码?
标签: java android listview android-listview