Note that there are some explanatory texts on larger screens.

plurals
  1. POWierd listview item selector appearance (pressed state was not removed when finger left the screen)
    primarykey
    data
    text
    <p>I have listview item like below</p> <pre><code>&lt;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" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/music_list_item_checkbox_bg" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><code>music_list_item_checkbox_bg.xml</code> is a selector which will show different drawable depending the different state.</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:state_pressed="false" android:state_selected="true" android:drawable="@drawable/btn_checkbox_check_untapped" /&gt; &lt;item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/btn_checkbox_check_tapped" /&gt; &lt;item android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/btn_checkbox_uncheck_untapped" /&gt; &lt;item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/btn_checkbox_uncheck_tapped" /&gt; &lt;/selector&gt; </code></pre> <p>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. </p> <p><em><strong>Question:</em></strong> 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).</p> <p>I tried add <code>android:duplicateParentState="true"</code> to the checkbox to get the same state with the parent, but it not works.</p> <p>I'm confused, Anyone have some ideas?</p> <p><strong>Edited</strong></p> <blockquote> <p>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.</p> </blockquote> <p>I really really want an solution!!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload