ListView and Buttons inside ListView

后端 未结 5 2268
花落未央
花落未央 2020-11-29 00:54

I want to display a Button inside the ListView. The goal should be to click on the ListView line or on the button.

Click on th

5条回答
  •  日久生厌
    2020-11-29 01:24

    Just to make this clear – and no one seems to have said something this simple – whilst one is not allowed to have a focusable button work in conjunction with the list view, there is a much simpler solution for this.

    The accepted answer is a given - you should always do that when setting the click listener for list items, so that is silly that OP didn't know that.

    If you are using an XML layout as your list item, simply set the button to have the following attribute and it will cause the list item to be clickable as well:

    android:focusable="false"

提交回复
热议问题