Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : ListView with Buttons -> OnItemClick do nothing

My problem come from ListView. Without Buttons, the .setOnItemClickListener of the ListView work well. (start an Activity)

At time that I add Buttons into items of the ListView, Buttons are clickable but the items aren't more clickable...

I try to use myListView.setItemCanFocus(true); but it don't work...

like image 300
Gregco Avatar asked Jun 08 '11 06:06

Gregco


3 Answers

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.

like image 166
liuyong Avatar answered Nov 03 '22 07:11

liuyong


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

like image 43
Stev_k Avatar answered Nov 03 '22 07:11

Stev_k


The reason is button in your listview absorbs the onItemClickEvent.

A well explained tutorial is here

like image 2
Ads Avatar answered Nov 03 '22 05:11

Ads