【发布时间】:2014-01-06 14:14:15
【问题描述】:
我有一个 ListView 和一个继承自 ArrayAdapter 的自定义 Adapter。我正在使用LinearLayout 的自定义Checkable 子类来突出显示列表中的最后一个选定项,它基本上将选中状态映射到选中状态。
Adapter 用于列表项的布局如下:
<com.wordlistdictionary.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<LinearLayout
android:id="@+id/entry_text"
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
/>
<TextView
android:id="@+id/entry_number_of_occurences_1"
android:textSize="9pt"
android:typeface="monospace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/item_text_color_selector"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:duplicateParentState="true"
/>
<TextView
android:id="@+id/entry_frequency_1"
android:textSize="9pt"
android:typeface="monospace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/item_text_color_selector"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:duplicateParentState="true"/>
<ImageButton
android:id="@+id/delete_entry_button_1"
android:src="@drawable/delete_button_selector"
android:layout_height="40dp"
android:layout_width="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="15dp"
android:duplicateParentState="true"
/>
</com.wordlistdictionary.CheckableLinearLayout>
在我添加最后一个ImageButton 视图之前,它会按照我的预期工作,最后一个触摸项目的文本颜色会发生变化,并且它会从该点停止突出显示文本。
有没有人遇到过这种情况,你的解决方案是什么?
目前我正在考虑一种解决方法,即手动将选定状态从我的自定义布局传播到所有子视图,而不是仅仅更改布局视图本身的选定状态并依赖duplicateParentState 机制。
【问题讨论】:
标签: android android-listview imagebutton