繁体   English   中英

Android ListView-具有1个按钮的列表项可以正常工作,添加imageButton则不可以

[英]Android listview - list item with 1 button works ok, adding an imagebutton is not ok

在列表视图中,我使用了带有1个按钮的行。 这很好。 我可以单击按钮并进行处理。 此外,我可以单击列表项,然后生成事件。 即使在列表上长按也可以。

添加imagebutton时 ,不会触发列表项单击或列表longpress事件。 为什么?

首先,您将看到工作正常的列表行(带有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添加到列表视图并不重要。

解决了...使用ImageButton时...我无法单击列表项。 通过一个按钮更改ImageButton,然后一切正常。

然后,您可以单击两个按钮,然后单击(或长按)列表行。

任何线索?

好吧,它有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM