Bol*_*rme 6 android listview clickable
我有两个按钮列表.当我想单击列表项时,它不起作用,但我的按钮仍然可以点击. 如何使所有按钮包括可点击的整个列表项?
项目清单:
<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>
Run Code Online (Sandbox Code Playgroud)
包含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>
Run Code Online (Sandbox Code Playgroud)
Fab*_* PH 28
对于按钮,复选框和ImageView:
android:focusable="false"
Run Code Online (Sandbox Code Playgroud)
现在,ListView的两个(按钮和行)都是可点击的.
对于ImageButtons,您必须在运行时设置焦点,因为ImageButtons的构造函数将其设置为true.我建议您使用ImageView而不是ImageButton.
<?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>
Run Code Online (Sandbox Code Playgroud)
现在您还可以将点击事件赋予相对布局。
| 归档时间: |
|
| 查看次数: |
7386 次 |
| 最近记录: |