我正在为名为 row.xml
的 listView
列表项使用自定义布局
这是我的 row.xml
文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical"
android:descendantFocusability="afterDescendants" >
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:textSize="40sp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:orientation="horizontal">
<Button
android:id="@+id/delete_btn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:gravity="right|center"
android:text="delete" />
</LinearLayout>
</LinearLayout>
在上面的布局中,onListItemClick()
方法不起作用,但是当我从布局中删除 Button
元素时,它可以正常工作。
请告诉我问题是什么
谢谢
最佳答案
在“Raghunandan”的帮助下,我添加了
android:focusable="false"
android:focusableInTouchMode="false"
到Button
,我的问题就解决了
Button
将焦点放在该行上,这就是我们无法选择该行的原因
关于android - onListItemClick() 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18169826/