Android : ListView with Buttons -> OnItemClick do nothing

别说谁变了你拦得住时间么 提交于 2019-12-03 06:13:18

Remove the focusable attribute from the Button would solve this problem. You could do that either in a layout xml file or java source code.

And one more tip, if you are using ImageButton instead of Button, you need setFocusable in your java code to make that work, cause the constructor of ImageButton would enabe this attribute after inflate from xml file.

Stev_k

It might be better to use an onTouch() callback for the clickable button within the listview. You should then be able to click.on both the list item and the button. See this question for some code (no need for touchDelegate).

The reason is button in your listview absorbs the onItemClickEvent.

A well explained tutorial is here

You can use this in .setOnItemClickListener of the ListView

view.findViewById(R.id.btn_id).setOnClickListener(new View.OnClickListener(){//your method})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!