ListView items are not clickable. why?

后端 未结 11 2432
借酒劲吻你
借酒劲吻你 2020-11-29 08:12

I have a ListView that uses a customized adapter, but I can\'t click on the ListView Item ..

Activity for list view ..

package com.adham         


        
相关标签:
11条回答
  • 2020-11-29 08:50

    I had the same issue with a ListView which contained only a RadioButton:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    
    <RadioButton
        android:id="@+id/userNameRadioButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    I used the RadioButton in each row to display the default item selection, to make ListView handle clicks I had to use:

    radioButton.setFocusableInTouchMode(false);
    radioButton.setFocusable(false);
    

    or in the XML-file:

    android:focusable="false" 
    android:focusableInTouchMode="false"
    

    So it is a focus related issue... With the above modifiers the focus is directed to ListView on click.

    0 讨论(0)
  • 2020-11-29 08:53

    Consider making the text value selectable by specifying android:textIsSelectable="true"

    Don't listen to Google. In the rows' layout, set

    textIsSelectable="false"

    Thank you Lint (not!)

    0 讨论(0)
  • 2020-11-29 08:54

    Android doesn't allow to select list items that have focusable elements (buttons). Modify the button's xml attribute to:

    android:focusable="false"
    

    It should still be clickable, just won't gain focus...

    0 讨论(0)
  • 2020-11-29 08:57

    set android:clickable="false" android:focusable="fasle"

    0 讨论(0)
  • 2020-11-29 09:00

    This answer here worked for me: https://stackoverflow.com/a/16536355/5112161

    Mainly he ADDED in the LinearLayout or RelativeLayout the following:

    android:descendantFocusability="blocksDescendants"
    

    You also need to REMOVE from all your xml the following:

    android:focusable="false"
    android:focusable="true"
    android:clickable="true"
    android:clickable="false"
    
    0 讨论(0)
提交回复
热议问题