Android Development Point drip--some basic but useful knowledge (2)

Source: Internet
Author: User

1.onItemLongClick and Onitemclick event interception

When you need to get an entry for a ListView in both long press events (Onitemlongclick) and click events (Onitemclick), justreturn to True in the Onitemlongclick event trigger function.


2. Customizing the checkbox style

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 customizing a ListView, each item has a button component or other component that can also be clicked (usually a button and a checkbox) on the other, since the focus is obtained by the button component, Then clicking on item is actually the equivalent of clicking on 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.