My Android step-by-step tour------>android in the ListView control when the Item's click event does not work as a workaround for the problem

Source: Internet
Author: User
<span id="Label3"></p><span style="white-space:pre"><span style="white-space:pre"></span></span><span style="line-height:27px"><span style="line-height:27px"></span></span><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="font-size:18px; color:rgb(51,51,51); font-family:宋体; line-height:19.5px"> <span style="white-space:pre"></span></span></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="color:rgb(51,51,51); line-height:19.5px"><span style="font-family:SimSun; font-size:18px"><strong><span style="white-space:pre"></span><span style="white-space:pre"></span><span style="white-space:pre"></span>Development often need to define their own listview, to inherit baseadapter, in the adapter in accordance with the requirements of the writing, the problem arises, may occur when clicking on each item when there is no response, unable to get the Focus.</strong></span></span></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="font-family:SimSun; font-size:18px"><strong>If you have a button in your custom listviewitem, <span style="white-space:pre"></span> <span style="white-space:pre"></span> </strong></span> <span style="font-family:SimSun; font-size:18px; color:rgb(51,51,51)"><strong>ImageButton</strong></span> <span style="font-family:SimSun; font-size:18px"><strong>or a checkable control, the default focus is given to the child control, and the ListView item can be selected based on its ability to get focus. </strong></span> <span style="font-family:SimSun; font-size:18px; color:rgb(51,51,51)"><strong>so often when clicking on item changes the child control, the item Itself's click does not respond. </strong></span></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="color:rgb(51,51,51); line-height:22px; text-align:justify; white-space:pre; font-family:SimSun; font-size:18px"><strong><span style="white-space:pre"></span><span style="white-space:pre"></span>At this point you can use the Descendantfocusability property to solve, he can set a control how to handle touch events,</strong></span></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="color:rgb(51,51,51); font-family:SimSun; font-size:18px; font-weight:bold; line-height:22px; text-align:justify; white-space:pre">This property is defined as the relationship between ViewGroup and its child controls when one gets the focus for the VIEW.</span></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="font-size:18px"><span style="color:rgb(51,51,51); line-height:19.5px; white-space:pre"><span style="color:rgb(51,51,51); line-height:22px; text-align:justify"></span></span></span></p></p><p style="margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; border:0px; line-height:22px; color:rgb(51,51,51); text-align:justify"><p style="margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; border:0px; line-height:22px; color:rgb(51,51,51); text-align:justify"><span style="font-family:SimSun"><strong><span style="white-space:pre"></span>There are three types of values for the Property:</strong></span></p></p><p style="font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; border:0px; line-height:22px; color:rgb(51,51,51); text-align:justify"><p style="font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; border:0px; line-height:22px; color:rgb(51,51,51); text-align:justify"></p></p><pre name="code" class="html"><pre name="code" class="html">Android:descendantfocusability= "blocksdescendants"//viewgroup overrides the subclass control and gets the focus directly android:focusable= "false" android: Descendantfocusability= "beforedescendants"//viewgroup takes precedence over its subclass control and gets to focus android:descendantfocusability= " Afterdescendants " //viewgroup gets focus only if its subclass control does not need to get focus</pre></pre><p><p></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="font-size:18px"><span style="white-space:pre"></span><span style="font-family:SimSun"><strong>So we can fix this by setting its android:descendantfocusability= "blocksdescendants" to the root control of item layout, so that the item Layout blocks all child controls from getting focus, so you can respond smoothly to the Onitenclick () method in Onitemclicklistener.</strong></span></span><br></p></p><p style="margin:10px auto; line-height:19.5px"><p style="margin:10px auto; line-height:19.5px"><span style="font-size:18px"><span style="color:rgb(51,51,51); font-family:宋体; line-height:19.5px"></span></span></p></p><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; text-align:justify"><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; text-align:justify"><span style="font-size:18px"></span></p></p><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; text-align:justify"><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; text-align:justify"><span style="font-size:18px"><br></span><span style="font-size:18px"></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><span style="font-size:18px">==================================================================================================</span></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><strong><span style="font-size:18px">Ouyangpeng welcome reprint, sharing with people is the source of progress!</span></strong></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><strong><span style="font-size:18px">Reprint please keep the original address <span style="color:rgb(153,51,153)">: Http://blog.csdn.net/ouyang_peng</span></span></strong></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:center; color:rgb(51,51,51); background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><span style="font-size:18px">==================================================================================================</span></span></p></p><p><p></p></p><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; font-size:14px; text-align:justify"><p style="border:0px; margin-top:8px; margin-bottom:8px; padding-top:0px; padding-bottom:0px; line-height:22px; color:rgb(51,51,51); font-family:‘Helvetica,Tahoma,Arial,sans-serif‘; font-size:14px; text-align:justify"><br></p></p><span style="font-family:FangSong_GB2312; font-size:24px"><span style="font-family:FangSong_GB2312; font-size:24px"><span style="color:rgb(51,51,51); line-height:22px"></span></span></span> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>My Android step-by-step tour------>android in the ListView control when the Item's click event does not work as a workaround for the problem</p></p></span>

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.