I have listview item like below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/music_list_item_checkbox_bg"
/>
</LinearLayout>
music_list_item_checkbox_bg.xml is a selector which will show different drawable depending the different state.
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="false"
android:state_selected="true"
android:drawable="@drawable/btn_checkbox_check_untapped" />
<item android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/btn_checkbox_check_tapped" />
<item android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/btn_checkbox_uncheck_untapped" />
<item android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/btn_checkbox_uncheck_tapped" />
</selector>
When i pressed the item in the listview and left the touch screen inside the item, the drawable depending on the different state is right.
Question: But if i pressed the item and move the finger horizontally out of the item (The X of touch point is between the top and bottom of the item), then left the screen, the drawable of the checkbox will remain in the state of pressed. (If the X of touch point is out of the top and bottom of the item, the state is right).
I tried add android:duplicateParentState="true" to the checkbox to get the same state with the parent, but it not works.
I’m confused, Anyone have some ideas?
Edited
I tried implements onTouch and onIntercept in the item before, but only can receive action down, if i return super.onTouch(MotionEvent event). Only return true, then the sequence event will received, but the onItemClick of listview could’t worked.
I try to read the onTouch code snippet in the AbsListview to figure out how to resolve the problem, i found sometimes the press status of child(item) will not to clear to false by calling child.setPressed(false) which depending on the different touch mode.
I really really want an solution!!!
I solve the problem but maybe not a good solution or official solution.
I use my own
MyListViewclass extends fromListViewinstead of the SDKListViewand receive theACTION_UPandACTION_CANCELin itsonTouchEvent, then set the press state of the item to false manually. More details to see the below code.