具有多个按钮的ListView,无法单击列表项 [英] ListView with multiple buttons, list item can't be clicked

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

问题描述

我有一个带有两个按钮的列表.当我想单击列表项时,它不起作用,但是我的按钮仍然可以单击.如何使所有按钮都包含整个列表项以供单击?

I have a list with two buttons in 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>

推荐答案

对于按钮复选框 ImageViews :

android:focusable="false"

现在既可以单击ListView,也可以单击按钮和行.

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

对于 ImageButtons ,您必须在运行时设置可聚焦,因为ImageButtons的构造函数将其设置为true.我建议您使用ImageView而不是ImageButton.

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天全站免登陆