在列表视图中,我使用了带有 1 个按钮的行。这工作正常。我可以单击按钮并处理它。此外,我可以单击列表项并生成事件。即使是列表中的长按也可以正常工作。
添加图像按钮时,不会触发列表项单击或列表长按事件。为什么?
首先,您将看到工作正常的列表行(带有 1 个按钮)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:padding="5dp"
android:background="@drawable/list_selector"
android:orientation="horizontal" >
<Button
android:id="@+id/answer_usable"
android:layout_width="40dp"
android:layout_weight="0"
style="@style/btnStyleGeocaching"
android:textSize="12sp"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginRight="5dp"
android:text="Set" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/variable"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="true"
android:layout_weight="1"
android:text=""
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/answer"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=""
android:textSize="20sp"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentRight="true"
android:singleLine="true"
android:textStyle="bold" >
</TextView>
</LinearLayout>
<TextView
android:id="@+id/formula"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text=""
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="13sp" >
</TextView>
</LinearLayout>
<!-- second button comes here -->
</LinearLayout>
在最后一个线性布局正上方的位置添加第二个图像按钮时,不会触发单击列表或长按。只有按钮接收按钮咔嗒声。
<ImageButton
android:id="@+id/variable_edit"
android:layout_width="40dp"
android:layout_weight="0"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_edit"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginLeft="5dp" />
列表视图为:
<ListView
android:id="@+id/fragment_vars_list"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="6dp"
android:choiceMode="singleChoice"
android:scrollbars="vertical" />
将 focusable=true 添加到列表视图并不重要。
解决了...使用图像按钮时...我无法单击列表项。通过按钮更改图像按钮,然后一切都按预期工作。
然后,您可以单击这两个按钮并单击(或长按)列表行。
有人知道吗?
嗯,它有效。