(安卓)的ListView有多个按钮,列表项不能点击 [英] (Android)listview with multiple buttons, list item can't be clicked

查看:101
本文介绍了(安卓)的ListView有多个按钮,列表项不能点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的名单,上面有两个按钮。当我想点击一个列表项这是行不通的,但我的按钮仍然是可点击。 我怎样才能让所有的按钮包括整个列表项被点击?

I have list with two buttons on it. When I want to click a list item it doesn't work, but my button is still clickable. How I can make all buttons include the entire list item to be 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>

含有ListView的布局:

Layout containing the 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>

推荐答案

对于按钮 Checkboxs ImageViews

android:focusable="false"

现在双方(按钮和行)ListView控件是可以点击的。

Now both (buttons and rows) of ListView are clickable.

对于 ImageButtons ,你必须运行时设置可成为焦点,因为ImageButtons的构造它设置为true。 我建议你​​使用的ImageButton的ImageView的替代。

For ImageButtons, you have to set focusable while running, because the constructor of ImageButtons sets it to true. I recommend you using a ImageView instead of a ImageButton.

这篇关于(安卓)的ListView有多个按钮,列表项不能点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆