Onitemclick event not responding in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.