Click on list item of a ListView doesn't respond

后端 未结 3 907
误落风尘
误落风尘 2020-12-17 04:14

I am implementing ListView in my code. But When I click on the items, it does not respond respond to the click in any way. Could someone help me please? Thanks

相关标签:
3条回答
  • 2020-12-17 04:32

    You should define on all of the child objects in the item listview (TextView, ImageView etc.):

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

    And for the root item RelativeLayout / LinearLayout and so, define:

    android:clickable="false"
    android:descendantFocusability="blocksDescendants"
    android:focusable="false"
    android:focusableInTouchMode="false"
    

    If you won't define those, they will "catch" the click event. And if you have a Custom listView adapter, just check that you override:

    @Override
    public boolean isEnabled(int position)
    {
        return true;
    }
    
    0 讨论(0)
  • 2020-12-17 04:32

    In my case a problem was in fact that a ListView contained HorizontalScrollViews.

    HSV consumes clicks over items and doesn't return OnItemClick to the ListView.

    I solved the problem when wrote an OnClickListener inside an adapter that returns a callback to the ListView. See here: https://stackoverflow.com/a/43653085/2914140.

    0 讨论(0)
  • 2020-12-17 04:42

    In the customer Item,

    set every element

    android:clickable="true"
    android:focusable="false"
    

    works for me

    0 讨论(0)
提交回复
热议问题