有没有办法使用标准的android xml文件(简单的列表项多项选择)并且只调整一些属性以便我也可以使用标准适配器?现在我创建了一个新的视图 xml 并从 simple_list_item_multiple_choice 复制了代码。在那里我只添加了背景颜色。这行得通,但现在我有两次几乎相同的代码。
我也知道自定义视图和自定义适配器会起作用,但我希望有一个更“智能”的解决方案(在我的情况下,真的只有背景颜色很重要,其余的都很好)。似乎更多的代码只用于更改项目的背景颜色。
我认为使用包含/合并标签我可以包含标准 xml 并证明我的需要,但这不起作用(也因为我不能再使用标准 arrayAdapter)
这就是我现在的视图:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:ellipsize="end"
android:singleLine="true"
android:background="@color/white"
/>