Recently in a à la carte Android app, to use the ListView, I would like to be able to work with a button in the ListView on the ordered dishes such as
I want to change the total number of dishes and the total price of the items shown on the left by clicking Add and Subtract.
But when I use the Onitemclick method, I find that the ListView does not respond:
This is really a pit.
On the internet for a long time to read a few blog posts, the solution roughly the following two kinds:
1. Set all child controls in the ListView's item Layout focusable property to False2. Set the property of the root control for item layout(recommended lightweight especially to modify someone else's code)android:descendantfocusability= "Blocksdescendant" so that the item layout blocks all child controls from gaining focus and does not need to target the item The Focusable property is reset for each control in layout because:If you have a button or a checkbox in your item, the focus is given to these child controls by default, and the ListView item can be selected based on its ability to get focus, so We can set the Focusable property of all controls contained in the item in the ListView to False so that the ListView item automatically gets the focus's permission, and it can be selected. It also responds to the Onitemclick () method in Onitemclicklistener.
It's not over yet, and I still don't respond after countless attempts. The problem was found in the ListView style file, where I used the Horizontalscrollview and the layout would cause both of these solutions to fail. The reason is unclear, if there is a big God see this rookie blog post, hope to be able to pointing twos.
There is also the root layout of the style file in the ListView if you use the Match_parent attribute then you must use this attribute in the <ListView/> tab of your overall presentation: Otherwise you will get an error.
Onitemclick events in Android do not respond