I'm having problems with button presses in ListView rows. The background attribute for each Button refers to a XML selector file; in order to select a different image on button presses.
I'm able to get press events from OnClickListener, but the state selector breaks and does not register presses with android:state_pressed="true"
and android:state_focused="false"
.
If I remove android:descendantFocusability="blocksDescendants"
from the parent/root Layout XML for the button; then the press state will work, but will fire no matter where you touch on the ListView row, which is annoying.
My problem: cannot manage the press/default states of rows separate from the buttons inside. They interfere with each other.
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainListLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
..........
Row item button further down:
<Button
android:id="@+id/deleteButton"
android:background="@drawable/del_button_selector"
.....
.....
/>
..........
And the drawable/del_button_selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/deleteico" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/deletepressed" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/deleteico" android:state_focused="false" android:state_pressed="true" />
Changing the drawable background in the last selector line there does not work. It will show the pressed image but it does not matter where you click on the row, away from the button.
I can change the background on button click events but I need to switch back to default background upon button release, which is hard to capture(?). If I can capture press/release events in listeners then that would be great for buttons only.
Any help appreciated! Thanks!