Android Development Point drops--some basic but practical knowledge (2)

Source: Internet
Author: User

1.onItemLongClick and Onitemclick event interception

When it is necessary to obtain a ListView entry Long press event (Onitemlongclick) and click event (Onitemclick), only the Onitemlongclick event trigger function is required,return True We can.


2. Define the checkbox style yourself

In the layout file, add a property to Android:button, say no more, directly on the code

  <checkbox                        android:id= "@+id/xxx"                        android:layout_width= "wrap_content"                        android:layout_height= "wrap _content "                        android:layout_marginright=" 5DP "                        android:button=" @drawable/checkbox_selector "                        android: text= "xxx"                        />
Checkbox_selector.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_checked=" true "                android:drawable=" @drawable/checkbox_selected_ Selector "/>    <item android:state_checked=" false "        android:drawable=" @drawable/checkbox_blank_ Selector "/></selector>
Checkbox_selected_selector.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_pressed=" true "                android:drawable=" @drawable/checkbox_ya "/>    <item android:state_pressed= "false"        android:drawable= "@drawable/checkbox_yz"/></selector>
Checkbox_blank_selector.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_pressed=" true "                android:drawable=" @drawable/checkbox_wa "/>    <item android:state_pressed= "false"        android:drawable= "@drawable/checkbox_wz"/></selector>


Focus issue with button or checkbox in Item 3.ListView

When you define a ListView, each item has a button component or other component that can also be clicked (usually a button and a checkbox), except that the text thinks there is one, and when you click on the item it may not respond, because the focus is obtained by the button component, When you click on item, it's actually the equivalent of clicking the button component.

Workaround: Add in the root layout of item

Android:descendantfocusability= "Blocksdescendants"


There is also a way to add a button component

Android:focusable= "false"




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.