8

我遇到了一个奇怪的问题,当我删除 Button 行时,我在我的 ListView 中添加了一个 Custom 行是可选的,但是当我添加 Button 时我无法单击该行,请参阅下面的 xml。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="77dp"
    android:layout_height="77dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:src="@drawable/company_logo" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="Idds  sdsad "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/imageView1"

    android:layout_below="@+id/textView1"
    android:textColor="#8b8989"
    android:layout_marginLeft="5dp"
    android:text="Tap to see detail"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:text="Button" />

请帮助为什么会发生这种情况。

4

2 回答 2

27

当您使用自定义行时。

在你的onclickListener中设置后,设置它的.buttongetViewfocusability false

button.setFocusable(false)

android:descendantFocusability="blocksDescendants"为您的行的布局容器设置。您可以直接设置android:focusable="false",但这会使您的按钮不可点击。

于 2013-04-20T11:14:32.997 回答
20

尝试设置

android:focusable="false"
android:focusableInTouchMode="false"

到你Button的 xml 中。获得焦点在行上,这Button就是为什么你不能选择你的行。

于 2013-04-20T11:12:40.310 回答