我的列表上有两个按钮。当我想单击列表项时,它不起作用,但我的按钮仍然可以点击。 如何让所有按钮都包含可点击的整个列表项?
列出项目:
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:mode="twoLine">
<Button
android:id="@+id/erase"
android:layout_width="40dip"
android:layout_height="40dip"
android:focusable="false"
android:focusableInTouchMode="false"/>
<ImageButton android:id="@+id/soundf"
android:layout_width="40dip"
android:layout_height="40dip"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView android:id="@+id/texxt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#CC0"/>
</TwoLineListItem>
包含ListView的布局:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/left"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="English to Indonesia"
android:layout_weight="1"
android:background="@drawable/chbutt" />
<Button android:id="@+id/right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Indonesia to English"
android:layout_weight="1"
android:background="@drawable/chbutt" />
</LinearLayout>
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/history"
android:headerDividersEnabled="false"
android:footerDividersEnabled="false"
android:isScrollContainer="false" />
</LinearLayout>
答案 0 :(得分:28)
对于按钮,复选框和 ImageViews :
android:focusable="false"
现在ListView的两个(按钮和行)都是可点击的。
对于 ImageButtons ,您必须在运行时设置焦点,因为ImageButtons的构造函数将其设置为true。 我建议你使用ImageView而不是ImageButton。
答案 1 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/rel1" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/erase"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
android:layout_width="40dip"
android:layout_height="40dip"
android:background="@drawable/closebtn"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<ImageButton android:id="@+id/soundf"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_below="@+id/erase"
android:layout_alignLeft="@+id/erase"
android:background="@drawable/soundinv"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<TextView android:id="@+id/texxt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/erase"
android:layout_alignTop="@+id/erase"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#CC0"
/>
<TextView android:id="@+id/texxt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/texxt1"
android:layout_alignLeft="@+id/texxt1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFF"
/>
</RelativeLayout>
现在您还可以将click事件提供给相对布局。
答案 2 :(得分:0)
只需将其添加到您的Java代码中:holder.yourButton.setFocusable(false);
我正在使用自己的cursorAdapter,因此我将代码行放在bindView
的末尾
这应该做到。