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"