我面临一个奇怪的问题,当我删除按钮行时,我在 ListView 中添加了一个自定义行,该行是可选的,但是当我添加按钮时,我无法单击该行,请参阅下面的 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" />
请帮助为什么会发生这种情况。
当您使用自定义行时。
设置后onclickListener
for button
在你的getView
,设置其focusability false
.
i.e button.setFocusable(false)
;
并且还设置了android:descendantFocusability="blocksDescendants"
对于您的行的布局容器。
可以直接设置android:focusable="false"
但这将使您的按钮不可点击。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)