Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

android - ListView with multiple buttons, list item can't be clicked

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?

List item:

<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>

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Buttons, Checkboxs and ImageViews:

android:focusable="false"

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...